题目链接:https://codeforces.com/contest/1360
A.Minimal Square
b站链接:https://www.bilibili.com/video/BV1b54y1D7Ra/
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=1000; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int n; scanf("%d",&n); int a,b; while(n--) { scanf("%d%d",&a,&b); if(2*a<=b) printf("%d ",b*b); else if(2*b<=a) printf("%d ",a*a); else{ int area=min(4*a*a,4*b*b); printf("%d ",area); } } return 0; }
B.Honest Coach
b站链接:https://www.bilibili.com/video/BV1D5411s7FE/
//------------------------------------------------- //Created by HanJinyu //Created Time :三 5/20 12:29:04 2020 //File Name :question.cpp //------------------------------------------------- #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn = 500005; int a[maxn],tree[4*maxn]; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); map<int,int>mp; int s[maxn]; for(int i=0;i<n;i++) { scanf("%d",s+i); mp[s[i]]++; } bool flag=false; for(auto it:mp) { if(it.second>1) { flag=true; break; } } if(flag) { printf("0 "); } else { sort(s,s+n); int b[maxn]; int ops=0; for(int i=1;i<n;i++) { b[ops++]=abs(s[i]-s[i-1]); } sort(b,b+n-1); printf("%d ",b[0]); } } return 0; }
C.Similar Pairs
b站链接:https://www.bilibili.com/video/BV1az4y1d77L
#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=3e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int a[100]; int _J=0,_O=0; for(int i=0;i<n;i++) { scanf("%d",a+i); if(a[i]&1) _J++; else _O++; } if(_J%2==0&&_O%2==0) { printf("YES "); } else { sort(a,a+n); bool flag=false; for(int i=1;i<n;i++) { if(abs(a[i]-a[i-1])==1) { flag=true; break; } } if(flag) printf("YES "); else printf("NO "); } } return 0; }
D.Buying Shovels
b站链接:https://www.bilibili.com/video/BV1SK4y1t7UT/
// // main.cpp // CF // // Created by HanJinyu on 2020/5/15. // Copyright © 2020 by HanJinyu. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=2e5+10; int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int t; scanf("%d",&t); while(t--) { ll n,k; scanf("%lld%lld",&n,&k); if(k>=n) printf("1 "); else if(k==1) printf("%lld ",n); else { if(n&1) { ll b[maxn]; int ops=0; for(int i=1;i<=sqrt(n);i++) { if(n%i==0) { b[ops++]=i; b[ops++]=n/i; } } sort(b,b+ops); for(int i=ops-1;i>=0;i--) { if(b[i]<=k) { printf("%lld ",n/b[i]); break; } } } else { if(n/2<=k) printf("2 "); else { if(n%k!=0) { ll b[maxn]; int ops=0; for(int i=1;i<=sqrt(n);i++) { if(n%i==0) { b[ops++]=i; b[ops++]=n/i; } } sort(b,b+ops); for(int i=ops-1;i>=0;i--) { if(b[i]<=k) { printf("%lld ",n/b[i]); break; } } } else { printf("%lld ",n/k); } } } } } return 0; }
E. Polygon
b站链接:https://www.bilibili.com/video/av625775165/
// // main.cpp // CF // // Created by 韩金宇 on 2020/5/15. // Copyright © 2020 韩金宇. All rights reserved. // #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <list> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; typedef double db; typedef long long ll; const int maxn=sqrt(100000); int main() { #ifdef ONLINE_JUDGE #else freopen("in.txt","r",stdin); #endif int T; scanf("%d",&T); while(T--) { int n; scanf("%d",&n); char a[400][400]; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { cin>>a[i][j]; } } bool flag=false; for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { if(a[i][j]=='1') { if(i==n-1||j==n-1) continue; else if(a[i+1][j]=='1'||a[i][j+1]=='1') continue; else { flag=true; break; } } } } if(flag) printf("NO "); else printf("YES "); } return 0; }