xiaomaolin's blog

By xiaomaolin, history, 4 weeks ago, In English,

昨天晚上第一次参加CF,提交成功两个题,排名5520.

standings 1257A - Two Rival Students 1257B - Magic Stick 1257C - Dominated Subarray

实际我们完成了第三题,但是并未成功上传。

A:很简单的意思,结果两种可能,l-r 或者 b-a+x。


#include<cstdio> #include<cmath> using namespace std; int main(){ int t,n,x,a,b,c,d,e; scanf("%d",&t); while(t--){ scanf("%d%d%d%d",&n,&x,&a,&b); c= abs(a-b); d=x+c; if(d>=n) printf("%d\n",n-1); else printf("%d\n",d); } return 0; }

B:题意不作解释。最后结果:只要m>=4,就能达到任何值。m = 3时,只能达到1,2,3;m = 2时,只能达到1,2,3;m = 1时,只能是1.



#include<stdio.h> int m,n; int flag = 1; int T; int main(){ scanf("%d",&T); while(T--){ scanf("%d%d",&m,&n); flag = 1; if(m >= 4) flag = 0; if(m == 3 && n <= 3) flag = 0; if(m == 2 && n <= 3) flag = 0; if(m == 1 && n == 1) flag = 0; if(flag) printf("NO\n"); else printf("YES\n"); } return 0; }

C:C最坑在题意,找一个最短的首尾相同的字串长度就行了,找不到返回-1.刚开始想的用优先队列,wa4,后来直接每一次判断:


#include<string.h> #include<stdio.h> #include<algorithm> using namespace std; #define maxn 200005 int ll[maxn]; int main(){ int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); int num; memset(ll,0,sizeof(ll)); if(n < 2) { for(int i = 0;i < n;i++){ scanf("%d",&num); } printf("-1\n"); } else{ int ans = 1e9; for(int i = 1;i <= n;i++){ scanf("%d",&num); if(ll[num] == 0) ll[num] = i; else { ans = min(ans,i &mdash; ll[num] + 1); ll[num] = i; } } if(ans == 1e9){ printf("-1\n"); } else{ printf("%d\n",ans); } } } return 0; }

第一次就写这么多了,好好学习,天天向上!!!

 
 
 
 
  • Vote: I like it
  • -34
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by xiaomaolin (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by xiaomaolin (previous revision, new revision, compare).

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

xia xỉa

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Well actually the so-called blog on CF is actually more similar to community.

So please do not use Chinese.