### xiaomaolin's blog

By xiaomaolin, history, 12 months ago,

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; }

• -34

 » 12 months ago, # |   0 Auto comment: topic has been updated by xiaomaolin (previous revision, new revision, compare).
 » 12 months ago, # |   0 Auto comment: topic has been updated by xiaomaolin (previous revision, new revision, compare).
 » 12 months ago, # |   0 xia xỉa
 » 12 months ago, # |   0 Well actually the so-called blog on CF is actually more similar to community.So please do not use Chinese.
•  » » 12 months ago, # ^ |   0 OK,I did known.
 » 7 months ago, # |   0 Sorry, I can't understand Chinese, Can you describe it in English.
 » 12 days ago, # |   0 不錯喔 一起加油