关键词:
A
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<bitset> 11 #include<set> 12 #define ll __int64 13 #define mod 100000000 14 #define N 5e6+10 15 #define M 1e 16 using namespace std; 17 int n,k; 18 int main() 19 { 20 freopen("input.txt","r",stdin); 21 freopen("output.txt","w",stdout); 22 scanf("%d %d",&n,&k); 23 printf("%d ",max((n*2+k-1)/k,2)); 24 25 return 0; 26 }
C
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<bitset> 11 #include<set> 12 #define ll __int64 13 #define mod 100000000 14 #define N 5e6+10 15 #define M 1e 16 using namespace std; 17 int h,w; 18 int x[250005],y[250005]; 19 int main() 20 { 21 freopen("input.txt","r",stdin); 22 freopen("output.txt","w",stdout); 23 int exm=0; 24 scanf("%d %d",&h,&w); 25 if(h<=1||w<=1) 26 { 27 printf("0 "); 28 return 0; 29 } 30 if(h%2==0){ 31 for(int i=h-1;i>=1;i-=2){ 32 for(int j=1;j<w;j++){ 33 x[exm]=i; 34 y[exm]=j; 35 exm++; 36 } 37 if(i!=1){ 38 x[exm]=i-1; 39 y[exm]=w-1; 40 exm++; 41 } 42 } 43 } 44 else{ 45 for(int i=h-1;i>=4;i-=2){ 46 for(int j=1;j<w;j++){ 47 x[exm]=i; 48 y[exm]=j; 49 exm++; 50 } 51 x[exm]=i-1; 52 y[exm]=w-1; 53 exm++; 54 } 55 for(int j=1;j<w;j+=2){ 56 if(j!=w-1){ 57 x[exm]=2; 58 y[exm]=j; 59 exm++; 60 x[exm]=1; 61 y[exm]=j; 62 exm++; 63 x[exm]=1; 64 y[exm]=j+1; 65 exm++; 66 } 67 else{ 68 x[exm]=2; 69 y[exm]=j; 70 exm++; 71 x[exm]=1; 72 y[exm]=j; 73 exm++; 74 } 75 } 76 } 77 printf("%d ",exm); 78 for(int i=0;i<exm;i++) 79 printf("%d %d ",x[i],y[i]); 80 return 0; 81 }
D
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<set> 11 using namespace std; 12 #define PI acos(-1.0) 13 typedef long long ll; 14 typedef pair<int,int> P; 15 const int maxn=1e4+100,maxm=1e5+100,inf=0x3f3f3f3f,mod=1e9+7; 16 const ll INF=1e13+7; 17 struct edge 18 { 19 int from,to; 20 int cost; 21 }; 22 edge es[maxm]; 23 priority_queue<P,vector<P>,greater<P> >que; 24 char s[200000]; 25 int main() 26 { 27 freopen("input.txt","r",stdin); 28 freopen("output.txt","w",stdout); 29 cin>>s; 30 int n=strlen(s); 31 int ans=1; 32 for(int i=1;i<n;i++) 33 { 34 if(s[i]==‘E‘&&(s[i-1]==‘N‘||s[i-1]==‘S‘)) ans=(ans*2)%mod; 35 else if(s[i]==‘W‘&&(s[i-1]==‘N‘||s[i-1]==‘S‘)) ans=(ans*2)%mod; 36 } 37 cout<<ans<<endl; 38 return 0; 39 }
E
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<bitset> 11 #include<set> 12 #define ll __int64 13 #define mod 100000000 14 #define N 5e6+10 15 #define M 1e 16 using namespace std; 17 ll n,k,a[100005]; 18 ll sum[100005]; 19 int main() 20 { 21 freopen("input.txt","r",stdin); 22 freopen("output.txt","w",stdout); 23 scanf("%I64d %I64d",&n,&k); 24 sum[0]=0; 25 ll maxn=0; 26 int pos; 27 for(ll i=1; i<=n; i++) 28 { 29 scanf("%I64d",&a[i]); 30 sum[i]=sum[i-1]+a[i]; 31 if(maxn<a[i]) 32 { 33 pos=i; 34 maxn=a[i]; 35 } 36 } 37 ll l,r; 38 ll ans1,ans2; 39 l=n-1+maxn; 40 r=sum[n]; 41 ans1=max(0ll,k-pos+1)/l; 42 ans2=max(0ll,k-sum[pos-1])/r; 43 for(ll i=0; i<=ans1; i++) 44 if(k>=(pos-1+l*i)&&k<=(sum[pos-1]+r*i)) 45 { 46 printf("YES "); 47 return 0; 48 } 49 printf("KEK "); 50 return 0; 51 }
F
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 using namespace std; 11 typedef pair<int,int> P; 12 typedef long long ll; 13 const int maxn=1e3+100,maxm=1e6+100,inf=0x3f3f3f3f,mod=1e9+7; 14 const ll INF=1e13+7; 15 struct edge 16 { 17 int from,to; 18 char ch; 19 }; 20 edge es[maxm]; 21 int pa[maxn]; 22 int findset(int x) 23 { 24 return pa[x]==x?x:pa[x]=findset(pa[x]); 25 } 26 void unit(int x,int y) 27 { 28 int fx=findset(x),fy=findset(y); 29 if(fx<=fy) pa[fx]=fy; 30 else pa[fy]=fx; 31 } 32 int in[maxn],out[maxn]; 33 int ans[maxn]; 34 int main() 35 { 36 freopen("input.txt","r",stdin); 37 freopen("output.txt","w",stdout); 38 int n,k; 39 scanf("%d%d",&n,&k); 40 for(int i=1; i<=n; i++) pa[i]=i; 41 memset(out,0,sizeof(out)); 42 memset(in,0,sizeof(in)); 43 for(int i=1; i<=k; i++) 44 { 45 scanf("%d%c%d",&es[i].from,&es[i].ch,&es[i].to); 46 if(es[i].ch==‘=‘) unit(es[i].from,es[i].to); 47 else 48 { 49 if(es[i].ch==‘>‘) swap(es[i].from,es[i].to); 50 es[i].ch=‘<‘; 51 } 52 } 53 for(int i=1; i<=k; i++) 54 { 55 if(es[i].ch==‘=‘) continue; 56 out[findset(es[i].from)]++,in[findset(es[i].to)]++; 57 } 58 for(int i=1; i<=n; i++) 59 if(in[i]&&out[i]) ans[i]=2; 60 for(int i=1; i<=k; i++) 61 { 62 if(es[i].ch==‘=‘) continue; 63 if(ans[findset(es[i].from)]==2) ans[findset(es[i].to)]=3; 64 else if(ans[findset(es[i].to)]==2) ans[findset(es[i].from)]=1; 65 } 66 for(int i=1; i<=n; i++) 67 { 68 if(ans[findset(i)]==1) cout<<"B"; 69 else if(ans[findset(i)]==2) cout<<"R"; 70 else if(ans[findset(i)]==3) cout<<"W"; 71 else cout<<"?"; 72 } 73 cout<<endl; 74 return 0; 75 }
G
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<bitset> 11 #include<set> 12 #define ll __int64 13 #define mod 100000000 14 #define N 5e6+10 15 #define M 1e 16 using namespace std; 17 int n; 18 int main() 19 { 20 freopen("input.txt","r",stdin); 21 freopen("output.txt","w",stdout); 22 scanf("%d",&n); 23 int que[1005]; 24 int jishu=0; 25 for(int i=2;i*i<=n;i++) 26 { 27 if(n%i==0) 28 { 29 int flag=0; 30 que[jishu++]=i; 31 while(n%i==0) 32 { 33 flag++; 34 n/=i; 35 if(flag>2) 36 { 37 printf("NO "); 38 return 0; 39 } 40 } 41 } 42 } 43 if(n>1) 44 que[jishu++]=n; 45 if(jishu==3) 46 printf("YES "); 47 else 48 printf("NO "); 49 return 0; 50 }
H
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 #include<bitset> 11 #include<set> 12 #define ll __int64 13 #define mod 100000000 14 #define N 5e6+10 15 #define M 1e 16 using namespace std; 17 int n; 18 int main() 19 { 20 freopen("input.txt","r",stdin); 21 freopen("output.txt","w",stdout); 22 scanf("%d",&n); 23 if(n<10) 24 { 25 ll ans=8; 26 for(int i=2;i<=n;i++) 27 ans*=9; 28 printf("%I64d ",ans); 29 } 30 else 31 { 32 ll ans=8; 33 for(int i=2;i<=9;i++) 34 ans*=9; 35 printf("%I64d",ans); 36 for(int i=10;i<=n;i++) 37 printf("0"); 38 printf(" "); 39 } 40 return 0; 41 }
J
1 #include<iostream> 2 #include<cstdio> 3 #include<cmath> 4 #include<cstring> 5 #include<algorithm> 6 #include<map> 7 #include<queue> 8 #include<stack> 9 #include<vector> 10 using namespace std; 11 typedef pair<int,int> P; 12 typedef long long ll; 13 const int maxn=1e3+100,maxm=1e6+100,inf=0x3f3f3f3f,mod=1e9+7; 14 const ll INF=1e13+7; 15 struct edge 16 { 17 int from,to; 18 char ch; 19 }; 20 edge es[maxm]; 21 char num[maxn][10]; 22 vector<int>G[maxn]; 23 int cy[maxn],vis[maxn]; 24 bool dfs(int u) 25 { 26 for(int i=0; i<G[u].size(); i++) 27 { 28 int v=G[u][i]; 29 if(vis[v]) continue; 30 vis[v]=true; 31 if(cy[v]==-1||dfs(cy[v])) 32 { 33 cy[v]=u; 34 return true; 35 } 36 } 37 return false; 38 } 39 int solve(int n) 40 { 41 int ret=0; 42 memset(cy,-1,sizeof(cy)); 43 for(int i=1; i<=n; i++) 44 { 45 memset(vis,0,sizeof(vis)); 46 if(dfs(i)) ret++; 47 } 48 return ret; 49 } 50 int main() 51 { 52 freopen("input.txt","r",stdin); 53 freopen("output.txt","w",stdout); 54 int n,m; 55 scanf("%d%d",&n,&m); 56 for(int i=1; i<=n; i++) scanf("%s",num[i]); 57 for(int i=1; i<=m; i++) scanf("%s",num[i+n]); 58 for(int i=1; i<=n; i++) 59 { 60 for(int j=1; j<=m; j++) 61 { 62 if(num[i][0]+num[i][1]+num[i][2]==num[j+n][3]+num[j+n][4]+num[j+n][5]) 63 G[i].push_back(j+n); 64 if(num[i][3]+num[i][4]+num[i][5]==num[j+n][0]+num[j+n][1]+num[j+n][2]) 65 G[i].push_back(j+n); 66 } 67 } 68 cout<<solve(n)<<endl; 69 for(int i=n+1; i<=n+m; i++) 70 { 71 if(cy[i]==-1)continue; 72 if(num[cy[i]][0]+num[cy[i]][1]+num[cy[i]][2]==num[i][3]+num[i][4]+num[i][5]) 73 cout<<"AT"<<" "<<num[cy[i]]<<" "<<num[i]<<endl; 74 else if(num[i][0]+num[i][1]+num[i][2]==num[cy[i]][3]+num[cy[i]][4]+num[cy[i]][5]) 75 cout<<"TA"<<" "<<num[i]<<" "<<num[cy[i]]<<endl; 76 } 77 return 0; 78 }
gym101243ecupcakes
http://codeforces.com/gym/101243/attachments题意:有n个人,桌子上有k的蛋糕,每个人都有一个值val,表示每次轮到他吃蛋糕时,他可以吃1~val的蛋糕量。在这n个人当中,val最大的人是最贪婪的,他每次都会固定的吃val蛋糕。现在一个一... 查看详情
codeforcesgym100269dwarftower(最短路)
题目连接:http://codeforces.com/gym/100269/attachmentsDescriptionLittleVasyaisplayinganewgamenamed“DwarfTower”.Inthisgametherearendifferentitems,whichyoucanputonyourdwarfcharacter.Itemsarenumberedfrom1ton. 查看详情
codeforcesgym100886jsockets
J- Sockets TimeLimit:1000MS MemoryLimit:262144KB 64bitIOFormat:%I64d&%I64uValerahasonlyoneelectricalsocketinhisflat.Healso 查看详情
codeforcesgym101063c
二进制转十进制然后按位比较 传送门 http://codeforces.com/gym/101063 #include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>#include<iostream>#include<sstream&g 查看详情
codeforcesgym-101147jwhistle'snewcar(代码片段)
DiscriptionStatementsWhistlehasboughtanewcar,whichhasaninfinitefueltankcapacity.Hediscoveredanirregularcountrysinceithas n citiesandthereareexactly n?-?1roadsbetweenthem,ofcourse,allcit 查看详情
codeforcesgym100952abcdefghij
A1#include<iostream>2#include<cstdio>3#include<cmath>4#include<cstring>5#include<algorithm>6#include<map>7#include<queue>8#include<stack>9#include<ve 查看详情
codeforcesgym100971dlayingcables(单调栈)
D- LayingCablesTimeLimit:2000MS MemoryLimit:262144KB 64bitIOFormat:%I64d&%I64uOne-dimensionalcountryhas n cities,the i 查看详情
codeforcesgym-100633jceizenpok’sformula
拓展Lucas1#include<cstdio>2#include<cstdlib>3#include<algorithm>4#include<cstring>5#include<vector>6#defineMAXN100000+107#definelllonglong8#definepbpush_back9#defineftfirst 查看详情
codeforcesgym100735deghi
http://codeforces.com/gym/100735D题直接暴力枚举感觉这道题数据有点问题为什么要先排下序才能过?不懂。。#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>#include<iostream>#include<sstr 查看详情
codeforcesgym100971abcfgkl
A题 直接把问号全部变为陆地如果所有陆地连通 那么再逐个把刚才变成陆地的问号变为水如果依旧连通有多种解为什么我的代码跑不过去,和网上的题解思路一模一样!!??#include<cstdio>#include<algorithm>#inclu... 查看详情
codeforcesgym101521ashuttlebus
题意:给定一个2*N的方格,从左上角开始走,有些格子不能走,问能否一次遍历所有能走的方格 在Gym上看到一场香港的比赛,很好奇就去看了一下,发现第一题很有趣,并且很水,似乎讨论一下奇偶性就行了,然后。。。我... 查看详情
codeforcesgym100685ccinderella(水题)
题意:给定n个杯子,里面有不同体积的水,然后问你要把所有的杯子的水的体积都一样,至少要倒少多少个杯子。析:既然最后都一样,那么先求平均数然后再数一下,哪个杯子的开始的体积就大于平均数,这是一定要倒的。... 查看详情
codeforcesgym100685iinnovativebusiness(贪心)
题意:给定一条路的长和宽,然后给你瓷砖的长和宽,你只能横着或者竖着铺,也可以切成片,但是每条边只能对应一条边,问你最少要多少瓷砖。析:先整块整块的放,然后再考虑剩下部分,剩下的再分成3部分,先横着,再... 查看详情
codeforcesgym101138d.strangequeries
Description给你一下长度为(n)的序列.(a_i=a_j)(l_1 leqslant ileqslantr_1)(l_2leqslant i leqslantr_2)询问满足条件的((i,j))对数.Sol分块+前缀和.非常乱搞啊...首先分块(O(sqrt{n}))一块.然后在每块里统计块中元素出现次数.先预处理 查看详情
codeforcesgym101156gnon-attackingqueens打表
题意求$n imesn$的棋盘上放$3$个皇后使得互相不攻击的方案数拓展是$m imesn$棋盘上放$k$皇后,暴力打表找到了公式OEIS代码importjava.math.BigInteger;importjava.util.Scanner;/***Createdbycyuunon2018/1/24.*/publicclassMain{publicstaticvoidmain(String[ 查看详情
2021-5-11csust周练codeforcesgym#102894(代码片段)
题目链接:https://codeforces.com/gym/102894文章目录A-BigBrotherIsWatchingYouB-SantaClausIsComingToTownC-SpecialChristmasCakeD-ImportantDocumentsE-TheCuriousCaseOfVasya(待会补上)F-HotelChevalierA-BigB 查看详情
codeforcesgym100357j(网络流)
题目大意 有n种物品,m种建筑,p个人。n,m,p∈[1,20] 每种建筑需要若干个若干种物品来建造。每个人打算建造一种建筑,拥有一些物品。 主角需要通过交易来建造自己的建筑,交易的前提是对方用多余的物品来换取... 查看详情
codeforcesgym100228graphofinversions
题目大意对于一个长为$N$的序列$A$,定义它所对应的逆序图:有$N$个点组成,标号为$1...N$的无向图,对于每一组$i,j(i<j)$若存在$A_i>A_j$则在新图中就存在一条$(A_i,A_j)$的无向边。现在给定一个$N(Nleq1000)$个点的图,保证它是某... 查看详情