【Codeforces Round #645 (Div. 2) B】Maria Breaks the Self-isolation
The Codeforces div round self
2023-09-14 09:03:42 时间
【题目翻译】
每个奶奶有个编号a[i]只有当操场上除了自己然后人数大于等于a[i]的时候,她才能出去。
(同时一起出去x个人的话,其余x-1个人也算是已经到操场上了)
然后问你最多能出去多少个人到操场上。
【题解】
这题不要想复杂了,你就直接想最后操场上有多少个人。设为x。那么肯定对于操场上每个人都应该满足a[i]<=x-1。
所以肯定可以一次性都到操场上去的,不用一次一次出去一拨人。
所以我们可以把a数组排个序,然后逆序枚举最大值x,找到a[i]<=x的最大的i,则x+1肯定就是答案了。
(排序让每次的a[i]都肯定是i个人的情况下最小的,逆序枚举找最大的!)
【代码】
#include<bits/stdc++.h>
#define ll long long
#define rei(x) scanf("%d",&x)
#define rel(x) scanf("%I64d",&x)
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
using namespace std;
const int N = 1e5;
int n,m;
int a[N+10];
int main(){
#ifdef LOCAL_DEFINE
freopen("D:\\rush.txt","r",stdin);
#endif
int T;
rei(T);
while (T--){
rei(n);
rep1(i,1,n) rei(a[i]);
sort(a+1,a+1+n);
int ans = 1;
rep2(x,n,1){
if (x>=a[x]){
ans = x+1;
break;
}
}
printf("%d\n",ans);
}
return 0;
}
相关文章
- SqlBulkCopy – The given value of type String from the data source cannot be converted to type
- 【已解决】spring boot项目从mysql中获取数据候错误The driver has not received any packets from the server
- django2 The custom handler404 view 'users.views.page_not_found' does not take the correct number of
- The unit caddy.service has entered the 'failed' state with result 'exit-code'
- 【错误记录】Android Studio 编译报错 ( The project is using an incompatible version (AGP 7.4.2) of the Androi )
- ORA-22900: the SELECT list item of THE subquery is not a collection type ORACLE 报错 故障修复 远程处理
- ORA-24047: invalid agent name string, agent name should be of the form NAME ORACLE 报错 故障修复 远程处理
- ORA-38408: The ADT “string” does not exist in the current schema. ORACLE 报错 故障修复 远程处理
- ORA-40003: wordsize must be in the range string – string for BLAST-P ORACLE 报错 故障修复 远程处理
- ORA-44733: The repository XML Index cannot be dropped directly ORACLE 报错 故障修复 远程处理
- ORA-46011: The value of the “selectPrivilege” element is too long. ORACLE 报错 故障修复 远程处理
- ORA-46014: The value of the “aclFile” element is too long. ORACLE 报错 故障修复 远程处理
- ORA-48408: The incident number exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48414: The string in the execution option exceeds maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-48489: The input exceeds the maximum length [string] ORACLE 报错 故障修复 远程处理
- ORA-53010: The value of the tag is null. ORACLE 报错 故障修复 远程处理
- ORA-55567: The _highthreshold_undoretention value should be at least string based on the current undo retention settings. ORACLE 报错 故障修复 远程处理
- ORA-55568: The maximum query length (mql) value should be atmost string based on the current _highthreshold_undoretention setting. ORACLE 报错 故障修复 远程处理
- ORA-13605: The specified task or object string does not exist for the current user. ORACLE 报错 故障修复 远程处理
- ORA-13638: The user interrupted the current operation. ORACLE 报错 故障修复 远程处理
- ORA-13703: The snapshot pair [string, string] for database_id string and instance_id string are not found in the current repository. ORACLE 报错 故障修复 远程处理
- ORA-13906: The tablespace is not of the right type. ORACLE 报错 故障修复 远程处理
- ORA-15247: cannot specify both WAIT and NOWAIT options in the same statement ORACLE 报错 故障修复 远程处理
- ORA-16790: the value of the configurable property is invalid ORACLE 报错 故障修复 远程处理
- PL/SQLUnlock the Power of Oracle PL/SQL: 01033.(01033oracle)
- Exploring the Power of Oracle Query Arrays: Tips and Techniques for Efficient Data Retrieval(oracle查询数组)
- Exploring the Ethernet Interface eth3 on Linux for Networking and Connectivity(linuxeth3)
- Exploring the Benefits and Advantages of Linux LDT for Modern Businesses(linuxldt)