标签:turn assert round hid sed back map com return
A,连续的1的个数就是每个位置上的数,注意0的处理,最后一个0不用删除
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100+10,maxn=500+100,inf=0x3f3f3f; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; string s; cin>>n>>s; int i=0; while(i<s.size()){ int j=i; while(j<s.size()&&s[j]==‘1‘)j++; cout<<j-i; i=j; while(j<s.size()&&s[j]==‘0‘)j++; int p=j-i; if(j!=s.size())p--; if(p>0) { while(p--)cout<<"0"; } i=j; // cout<<i<<endl; } cout<<endl; return 0; } /******************** ********************/
B,放一个点能有连续5个x,直接暴力
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100+10,maxn=500+100,inf=0x3f3f3f; char ma[N][N]; bool ok(int x,int y) { if(x<=6) { int a=0,b=0; for(int i=0;i<5;i++) { if(ma[x+i][y]==‘X‘)a++; else if(ma[x+i][y]==‘O‘)b++; } if(b==0&&a>=4)return 1; } if(y<=6) { int a=0,b=0; for(int i=0;i<5;i++) { if(ma[x][y+i]==‘X‘)a++; else if(ma[x][y+i]==‘O‘)b++; } if(b==0&&a>=4)return 1; } if(x<=6&&y<=6) { int a=0,b=0; for(int i=0;i<5;i++) { if(ma[x+i][y+i]==‘X‘)a++; else if(ma[x+i][y+i]==‘O‘)b++; } if(b==0&&a>=4)return 1; } if(x>=4&&y<=6) { int a=0,b=0; for(int i=0;i<5;i++) { if(ma[x-i][y+i]==‘X‘)a++; else if(ma[x-i][y+i]==‘O‘)b++; } if(b==0&&a>=4)return 1; } return 0; } int main() { ios::sync_with_stdio(false); cin.tie(0); for(int i=1;i<=10;i++) for(int j=1;j<=10;j++) cin>>ma[i][j]; for(int i=1;i<=10;i++) { for(int j=1;j<=10;j++) { if(ok(i,j)) { // cout<<i<<" "<<j<<endl; cout<<"YES"<<endl; return 0; } } } cout<<"NO"<<endl; return 0; } /******************** XXOXX..... OOXOO..... ....XX.... ....OO.... ...XOOX... ..XO..OX.. OX......XO XO..XX..OX ....OO.... .......... ********************/
C,模拟
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000+10,maxn=500+100,inf=0x3f3f3f; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,k; cin>>n>>k; for(int i=0;i<n;i++)cin>>a[i]; sort(a,a+n); ll ans=0; for(int i=0;i<n;i++) { if(a[i]<=k)continue; else if(k<a[i]&&a[i]<=2*k)k=a[i]; else { while(2*k<a[i])k*=2,ans++; k=a[i]; } } cout<<ans<<endl; return 0; } /******************** 2 1 3 6 ********************/
D、二分倍数,用一个容器存答案,然后输出即可
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=1000+10,maxn=500+100,inf=0x3f3f3f; ll a[N]; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,k; cin>>n>>k; for(int i=0;i<n;i++)cin>>a[i]; sort(a,a+n); ll ans=0; for(int i=0;i<n;i++) { if(a[i]<=k)continue; else if(k<a[i]&&a[i]<=2*k)k=a[i]; else { while(2*k<a[i])k*=2,ans++; k=a[i]; } } cout<<ans<<endl; return 0; } /******************** 2 1 3 6 ********************/
E,拓扑排序,记录出度,优先队列从大到小排
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cassert> #include<iomanip> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define C 0.5772156649 #define pi acos(-1.0) #define ll long long #define mod 1000000007 #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const double g=10.0,eps=1e-7; const int N=100000+10,maxn=500+100,inf=0x3f3f3f; vector<int>v[N]; int lab[N],out[N],n; void bfs() { priority_queue<int,vector<int>,less<int> >q; memset(lab,-1,sizeof lab); int res=n; for(int i=1;i<=n;i++) if(out[i]==0) q.push(i); while(!q.empty()){ int k=q.top(); lab[k]=res--; q.pop(); for(int i=0;i<v[k].size();i++) { out[v[k][i]]--; if(out[v[k][i]]==0)q.push(v[k][i]); } } } int main() { ios::sync_with_stdio(false); cin.tie(0); int m; cin>>n>>m; for(int i=0;i<m;i++) { int a,b; cin>>a>>b; v[b].push_back(a); out[a]++; } bfs(); for(int i=1;i<=n;i++) cout<<lab[i]<<" "; cout<<endl; return 0; } /******************** ********************/
Educational Codeforces Round 25
标签:turn assert round hid sed back map com return
原文地址:http://www.cnblogs.com/acjiumeng/p/7273212.html