3 条题解
-
1
When I don't know the final answer to this question, first of all, there are individuals left
Then we obviously need to use a number to eat the first number smaller than it
We are considering how to complete this task. First, sort and discretize it, and then do it casually
Mainly based on the game code:
#include<algorithm> #include<iostream> #include<cstdio> using namespace std; const int N=1e5+10; int n,cnt=0,ans=0,ret=0; int a[N],ton[N]; int reads(){ char c=getchar(); int sum=0,f=1; while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ sum=(sum<<3)+(sum<<1)+c-'0'; c=getchar(); } return sum*f; } void files(){ freopen("duel.in","r",stdin); freopen("duel.out","w",stdout); } signed main(){ // files(); n=reads(); ans=n; for(int i=1;i<=n;i++){ a[i]=reads(); ton[a[i]]++; } sort(a+1,a+n+1); cnt=unique(a+1,a+n+1)-a-1; for(int i=2;i<=cnt;i++){ if(ton[a[i]]>=ton[a[i-1]]){ ans-=ton[a[i-1]]; int t=ton[a[i]]-ton[a[i-1]]; ans-=min(ret,t); ret-=min(ret,t); } else{ ans-=ton[a[i]]; ret+=(ton[a[i-1]]-ton[a[i]]); } } printf("%d\n",ans); return 0; } -
1
這道題考慮首先我不知道最後的答案的時候,首先剩下個人
然後我們顯然是要用一個數吃掉第一個比它小的數
我們考慮如何完成這個事情,首先排序+離散化,然後隨便做就好了
主要看賽時程式碼:
#include<algorithm> #include<iostream> #include<cstdio> using namespace std; const int N=1e5+10; int n,cnt=0,ans=0,ret=0; int a[N],ton[N]; int reads(){ char c=getchar(); int sum=0,f=1; while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ sum=(sum<<3)+(sum<<1)+c-'0'; c=getchar(); } return sum*f; } void files(){ freopen("duel.in","r",stdin); freopen("duel.out","w",stdout); } signed main(){ // files(); n=reads(); ans=n; for(int i=1;i<=n;i++){ a[i]=reads(); ton[a[i]]++; } sort(a+1,a+n+1); cnt=unique(a+1,a+n+1)-a-1; for(int i=2;i<=cnt;i++){ if(ton[a[i]]>=ton[a[i-1]]){ ans-=ton[a[i-1]]; int t=ton[a[i]]-ton[a[i-1]]; ans-=min(ret,t); ret-=min(ret,t); } else{ ans-=ton[a[i]]; ret+=(ton[a[i-1]]-ton[a[i]]); } } printf("%d\n",ans); return 0; } -
0
这道题考虑首先我不知道最后的答案的时候,首先剩下 个人
然后我们显然是要用一个数 吃掉第一个比它小的数
我们考虑如何完成这个事情,首先排序+离散化,然后随便做就好了
主要看赛时代码:
#include<algorithm> #include<iostream> #include<cstdio> using namespace std; const int N=1e5+10; int n,cnt=0,ans=0,ret=0; int a[N],ton[N]; int reads(){ char c=getchar(); int sum=0,f=1; while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ sum=(sum<<3)+(sum<<1)+c-'0'; c=getchar(); } return sum*f; } void files(){ freopen("duel.in","r",stdin); freopen("duel.out","w",stdout); } signed main(){ // files(); n=reads(); ans=n; for(int i=1;i<=n;i++){ a[i]=reads(); ton[a[i]]++; } sort(a+1,a+n+1); cnt=unique(a+1,a+n+1)-a-1; for(int i=2;i<=cnt;i++){ if(ton[a[i]]>=ton[a[i-1]]){ ans-=ton[a[i-1]]; int t=ton[a[i]]-ton[a[i-1]]; ans-=min(ret,t); ret-=min(ret,t); } else{ ans-=ton[a[i]]; ret+=(ton[a[i-1]]-ton[a[i]]); } } printf("%d\n",ans); return 0; }
- 1
信息
- ID
- 494
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- (无)
- 递交数
- 5
- 已通过
- 4
- 上传者