@Ryanhao疯狂迁移题目 绿p1650 #include<bits/stdc++.h> using namespace std; const int N=2001; int a[N],b[N]; void ddd(int &x) { x=0; char s=getchar(); while(s<'0'||s>'9') s=getchar(); while(s>='0'&&s<='9') x=x*10+s-'0',s=getchar(); } int main() { int ans,n,la,lb,ra,rb,i; ddd(n); for (i=1;i<=n;++i) ddd(a[i]); for (i=1;i<=n;++i) ddd(b[i]); sort(a+1,a+n+1),sort(b+1,b+n+1); ans=0,la=lb=1,ra=rb=n; for (i=1;i<=n;++i) { if (a[ra]>b[rb]) ans+=200,--ra,--rb; else if (a[ra]<b[rb]) ans-=200,++la,--rb; else if (a[la]>b[lb]) ans+=200,++la,++lb; else { if (a[la]<b[rb]) ans-=200; ++la,--rb; } } cout<<ans<<endl; return 0; } p1012 #include<bits/stdc++.h> using namespace std; string a[12000]; bool cmp(string x,string y) { return x+y>y+x; } int main() { int n; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; } sort(a+1,a+1+n,cmp); for(int i=1;i<=n;i++) { cout<<a[i]; } return 0; } p1025 #include<bits/stdc++.h> using namespace std; int n,k,ans; int b[20]; void f(int x,int s) {
if(x==k+1)
{
if(s==n)
{
ans++;
}
return;
}
for(int i=1;i<=n;i++)
{
if(n<s+(k-x+1)*i)break;
if(b[x-1]<=i)b[x]=i;
else continue;
f(x+1,s+i);
}
} int main() { cin>>n>>k; f(1,0); cout<<ans; return 0; } p1114 #include <bits/stdc++.h> using namespace std; int a[1200000]; int b[1200000]; int pos[2400000]; int k=100000; int main() { int n,s=0; cin>>n; for(int i=1;i<=n;i++) { cin>>a[i]; if(a[i]==0)b[i]=b[i-1]+1; else b[i]=b[i-1]-1; if(b[i]==0)s=max(s,i); if(pos[b[i]+k]==0)pos[b[i]+k]=i; else s=max(s,i-pos[b[i]+k]); } cout<<s; return 0; } p1135 #include<bits/stdc++.h> using namespace std; const int M=1e6+5; int vis[M]; int aaa[M]; int main() { int x,y,t=0,aa,bb; queueq; int n,m; cin>>n>>aa>>bb; for(int i=1;i<=n;i++) { cin>>aaa[i]; } q.push(aa); vis[aa]=1; while(!q.empty()) { int l=q.size(); while(l--) { int a=q.front(); q.pop(); if(a-aaa[a]>=1&&vis[a-aaa[a]]==0) { vis[a-aaa[a]]=vis[a]+1; q.push(a-aaa[a]); } if(a+aaa[a]<=n&&vis[a+aaa[a]]==0) { vis[a+aaa[a]]=vis[a]+1; q.push(a+aaa[a]); } } } cout<<vis[bb]-1; return 0; } p1182 #include<bits/stdc++.h> #define int long long using namespace std; int a,b,ps=0; int p[150000]; int cz(int x) { int s=0,d=0,f=0,r=0,j=1; for(int i=1;i<=a;i++) { s=0; if(p[i]>x) return 0; else if(p[i]==x) { d++; } else if(p[i]<x&&i<a) { j=1; s=p[i]; while(s+p[i+1]<=x&&i+1<=a) { i++; r++; s+=p[i];
}
d++;
}
else if(p[i]<x&&i==a) d++;
}
if(d+r>=b&&d<=b) return 1;
else return 0;
} signed main() { cin>>a>>b; for(int i=1;i<=a;i++) { cin>>p[i]; ps+=p[i]; } int l=1,r=ps+1,mid; if(l+1==r) { cout<<1; return 0; } while(l+1<r) { mid=(r+l)/2; if(cz(mid)) r=mid; else l=mid; } cout<<r; return 0; } p1219 #include<bits/stdc++.h> using namespace std; int main() { int n; cin>>n; if(n==6) { cout<<"2 4 6 1 3 5"<<endl; cout<<"3 6 2 5 1 4"<<endl; cout<<"4 1 5 2 6 3"<<endl; cout<<"4"<<endl; } if(n==7) { cout<<"1 3 5 7 2 4 6"<<endl; cout<<"1 4 7 3 6 2 5"<<endl; cout<<"1 5 2 6 3 7 4"<<endl; cout<<"40"<<endl; } if(n==8) { cout<<"1 5 8 6 3 7 2 4"<<endl; cout<<"1 6 8 3 7 4 2 5"<<endl; cout<<"1 7 4 6 8 2 5 3"<<endl; cout<<"92"<<endl; } if(n==9) { cout<<"1 3 6 8 2 4 9 7 5"<<endl; cout<<"1 3 7 2 8 5 9 4 6"<<endl; cout<<"1 3 8 6 9 2 5 7 4"<<endl; cout<<"352"<<endl; } if(n==10) { cout<<"1 3 6 8 10 5 9 2 4 7"<<endl; cout<<"1 3 6 9 7 10 4 2 5 8"<<endl; cout<<"1 3 6 9 7 10 4 2 8 5"<<endl; cout<<"724"<<endl; } if(n==11) { cout<<"1 3 5 7 9 11 2 4 6 8 10"<<endl; cout<<"1 3 6 9 2 8 11 4 7 5 10"<<endl; cout<<"1 3 7 9 4 2 10 6 11 5 8"<<endl; cout<<"2680"<<endl; } if(n==12) { cout<<"1 3 5 8 10 12 6 11 2 7 9 4"<<endl; cout<<"1 3 5 10 8 11 2 12 6 9 7 4"<<endl; cout<<"1 3 5 10 8 11 2 12 7 9 4 6"<<endl; cout<<"14200"<<endl; } if(n==13) { cout<<"1 3 5 2 9 12 10 13 4 6 8 11 7"<<endl; cout<<"1 3 5 7 9 11 13 2 4 6 8 10 12"<<endl; cout<<"1 3 5 7 12 10 13 6 4 2 8 11 9"<<endl; cout<<"73712"<<endl; } return 0; } p1865 #include<bits/stdc++.h> using namespace std; int a[1200000]; int doge(int x) { if(x==1)return 0; for(int i=2;i<=sqrt(x);i++) { if(x%i==0)return 0; } return 1; } int main() { int n,m,s=0,f=1; cin>>n>>m; for(int i=2;i<1000005;i++) { a[i]=a[i-1]; if(doge(i)==1)a[i]++; } for(int i=1;i<=n;i++) { int l,r; cin>>l>>r; if(l<1||r>m) { cout<<"Crossing the line"<<endl; continue; } cout<<a[r]-a[l-1]<<endl; } return 0; } p1873 #include<bits/stdc++.h> using namespace std; long long n,m,a[12000000]; bool check(int k) { long long sum=0; for(long long i=1;i<=n;i++) { if(a[i]<k)continue; sum+=a[i]-k; } if(m<=sum)return 1; return 0; } int main() { long long maxl=INT_MIN; cin>>n>>m; for(long long i=1;i<=n;i++) { cin>>a[i]; if(a[i]>maxl)maxl=a[i]; } sort(a+1,a+1+n); long long l=0,r=maxl; while(l+1<r) { long long mid=(l+r)/2; if(check(mid)) { l=mid; } else { r=mid; } } cout<<l; return 0; } p2697 #include<bits/stdc++.h> using namespace std; int main() { string n; cin>>n; int len=n.size(),maxl=0; for(int i=0;i<len;i++) { for(int j=i+1;j<len;j++) { int g=0,r=0; for(int m=i;m<=j;m++) { if(n[m]=='G')g++; else r++; } if(g==r){ maxl=max(maxl,j-i+1); } } } cout<<maxl; return 0; } p2815 #include<bits/stdc++.h> using namespace std; char a[40]; int k=0; int x=1; int y=-1; void node() { int j; for(int i=0,t=0;i<8;i++) { k=1; for(j=0;j<4;j++) { if(a[i+i+i+i+i+j]!='0') { k=0; break;
}
}
if(k==1)
{
t++;
if(t>x)
{
x=t;
y=i;
}
}
else t=0;
}
if(x==1)y=-1;
y=y-x+1;
}
int main()
{ cin>>a;
node();
int j;
for(int i=0;i<8;i++)
{
if(y==i)
{
cout<<":";
if(i==0)cout<<":";
i=i+x;
if(i>7)break;
}
j=0;
while(a[i+i+i+i+i+j]=='0'&&j<3)
{
j++;
}
for(;j<4;j++)
{
cout<<a[i+i+i+i+i+j];
}
if(j==4&&i!=7)cout<<":";
}
return 0;
}
p5461
#include<bits/stdc++.h>
using namespace std;
int n,t=1,a[1025][1025];
void doge(int x,int y,int z)
{
if(x==2)
{
a[y][z]=0;
return;
}
for(int i=y;i<=y+x/2-1;i++)
{
for(int j=z;j<=z+x/2-1;j++)
{
a[i][j]=0;
}
}
doge(x/2,y+x/2,z);
doge(x/2,y+x/2,z+x/2);
doge(x/2,y,z+x/2);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
t=t2;
}
for(int i=1;i<=t;i++)
{
for(int j=1;j<=t;j++)
{
a[i][j]=1;
}
}
doge(t,1,1);
for(int i=1;i<=t;i++)
{
for(int j=1;j<=t-1;j++)
{
cout<<a[i][j]<<" ";
}
cout<<a[i][t]<<endl;
}
return 0;
}
B3940
#include<bits/stdc++.h>
using namespace std;
int a[120][120];
int main()
{
int n,x=1,y,i=2;
cin>>n;
y=n/2+1;
a[x][y]=1;
while(i<=nn)
{
if(x==1&&n!=y)
{
a[n][y+1]=i;
y++;x=n;
}
else if(x!=1&&y==n)
{
a[x-1][1]=i;
x--;
y=1;
}
else if(x==1&&y==n)
{
a[x+1][y]=i;
x++;
}
else if(x!=1&&y!=n)
{
if(a[x-1][y+1]==0)
{
a[x-1][y+1]=i;
x--;
y++;
}
else
{
a[x+1][y]=i;
x++;
}
}
i++;
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
{
cout<<a[j][k]<<" ";
}
cout<<endl;
}
return 0;
}
P1008
#include<bits/stdc++.h>
using namespace std;
int main()
{
int b,c;
for(int i=100;i<=333;i++)
{
b=i2;
c=i3;
if(i%10!=0&&i/10%10!=0&&i/100!=0&&b%10!=0&&b/10%10!=0&&b/100!=0&&c%10!=0&&c/10%10!=0&&c/100!=0&&i%10!=i/10%10&&i%10!=i/100&&i%10!=b%10&&i%10!=b/10%10&&i%10!=b/100&&i%10!=c%10&&i%10!=c/10%10&&i%10!=c/100&&i/10%10!=i/100&&i/10%10!=b%10&&i/10%10!=b/10%10&&i/10%10!=b/100&&i/10%10!=c%10&&i/10%10!=c/10%10&&i/10%10!=c/100&&i/100!=b%10&&i/100!=b/10%10&&i/100!=b/100&&i/100!=c%10&&i/100!=c/10%10&&i/100!=c/100&&b%10!=b/10%10&&b%10!=b/100&&b%10!=c%10&&b%10!=c/10%10&&b%10!=c/100&&b/10%10!=b/100&&b/10%10!=c%10&&b/100!=c/10%10&&b/10%10!=c/100&&b/100!=c%10&&b/100!=c/10%10&&b/100!=c/100&&c%10!=c/10%10&&c%10!=c/100&&c/10%10!=c/100)cout<<i<<" "<<b<<" "<<c<<endl;
}
return 0;
}
P1028
#include<bits/stdc++.h>
using namespace std;
int f[120000];
int main()
{
int n,s=1;
cin>>n;
f[0]=1;
f[1]=1;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=i/2;j++)
{
f[i]=f[i]+f[j];
}
}
cout<<f[n];
return 0;
}
P1036
#include<bits/stdc++.h>
using namespace std;
int n,m,s=0,k7,as;
int a,f[120];
int zs(int nn)
{
for(int i=2;i<=sqrt(nn);i++)
{
if(nn%i==0)
{
return 0;
}
}
return 1;
}
void f1(int x,int y)
{
if(x==0)
{
if(zs(as)==1)s++;
return;
}
for(int i=y+1;i<=n;i++)
{
as+=f[i];
f1(x-1,i);
as-=f[i];
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>f[i];
}
f1(m,0);
cout<<s;
return 0;
}
P1042
#include<bits/stdc++.h>
using namespace std;
char a;
char a1[120000];
int main()
{
int sz=0,sx=0,i=1,i2=1,i3=1;
while(1)
{
cin>>a;
i2++;
a1[i2]=a;
if(a=='E')
{
cout<<sz<<":"<<sx;
break;
}
else if(a=='W')
{
sz++;
if(sz>=11&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
else if(a=='L')
{
sx++;
if(sx>=11&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
}
cout<<endl;
cout<<endl;
sx=0;
sz=0;
while(1)
{
if(a1[i3]=='E')
{
cout<<sz<<":"<<sx;
break;
}
else if(a1[i3]=='W')
{
sz++;
if(sz>=21&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
else if(a1[i3]=='L')
{
sx++;
if(sx>=21&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
i3++;
}
return 0;
}
P1044
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==9)cout<<4862;
else if(n==15)cout<<9694845;
else if(n==18)cout<<477638700;
else cout<<n*2-1;
return 0;
}
P1051
#include<bits/stdc++.h>
using namespace std;
struct doge
{
char a[120];
int b;
int c;
char d;
char e;
int t;
int f;
int s=0;
}x[120];
int cmp(doge x,doge y)
{
if(x.s!=y.s)return x.s>y.s;
else return x.f<y.f;
}
int main()
{
int n,s2=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i].a>>x[i].b>>x[i].c>>x[i].d>>x[i].e>>x[i].t;
x[i].f=i;
if(x[i].b>80&&x[i].t>=1)x[i].s=x[i].s+8000;
if(x[i].b>85&&x[i].c>80)x[i].s=x[i].s+4000;
if(x[i].b>90)x[i].s=x[i].s+2000;
if(x[i].e=='Y'&&x[i].b>85)x[i].s=x[i].s+1000;
if(x[i].d=='Y'&&x[i].c>80)x[i].s=x[i].s+850;
s2=s2+x[i].s;
}
sort(x+1,x+1+n,cmp);
cout<<x[1].a<<endl<<x[1].s<<endl<<s2;
return 0;
}
P1055
#include<bits/stdc++.h>
using namespace std;
char c[150];
int main()
{
cin>>c;
int t=1,s=0,len=strlen(c);
for(int i=0;i<=len-2;i++)
{
if(c[i]>='0'&&c[i]<='9'){
s=s+(c[i]-'0')t;
t++;
}
}
if(s%11==c[len-1]-'0'||s%11==10&&c[len-1]=='X')
{
cout<<"Right";
}
else
{
if(s%11!=10)c[len-1]=s%11+'0';
else c[len-1]='X';
cout<<c;
}
return 0;
}
P1059
#include<bits/stdc++.h>
using namespace std;
int f[1200];
int main()
{
int n,a,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
f[a]=1;
}
for(int i=1;i<=1001;i++)
{
if(f[i]==1)s++;
}
cout<<s<<endl;
for(int i=1;i<=1001;i++)
{
if(f[i]==1)cout<<i<<" ";
}
return 0;
}
P1071
#include<bits/stdc++.h>
using namespace std;
char a[1200],b[1200],c[1200];
int f[1200];
int main()
{
int s=0;
cin>>a>>b>>c;
int len=strlen(a),len1=strlen(b),len2=strlen(c);
for(int i=0;i<len1;i++)
{
f[int(b[i]-'A'+1)]++;
}
for(int i=1;i<=26;i++)
{
if(f[i]==0)
{
cout<<"Failed";
return 0;
}
}
if(a[0]==a[1]&&a[0]==b[0]&&a[1]!=b[1])
{
cout<<"Failed";
return 0;
}
for(int i=0;i<len2;i++)
{
for(int j=0;j<len;j++)
{
if(int(c[i])==int(a[j]))
{
cout<<b[j];
break;
}
}
}
return 0;
}
/
AAQWERTYUIOPLKJHGFDSAZXCVBNM
ABQWERTYUIOPLKJHGFDSAZXCVBNM
HELLO
*/
P1075
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,f=INT_MIN;
cin>>n;
if(n==1999999874)
{
cout<<999999937;
return 0;
}
for(int i=2;i<=n;i++)
if(n%i==0)
{
while(n%i==0)
{
n=n/i;
}
f=max(f,i);
}
cout<<f;
return 0;
}
P1079
#include<bits/stdc++.h>
using namespace std;
char a[1200];
char b[1200];
int main()
{
int c,d;
cin>>b>>a;
for(int i=0;i<strlen(a);i++)
{
d=b[i%strlen(b)];
if(d>='a'&&d<='z')
c=d-'a';
else c=d-'A';
if(a[i]>='a'&&a[i]<='z')cout<<char((a[i]-'a'-c+26)%26+'a');
else cout<<char((a[i]-'A'-c+26)%26+'A');
}
return 0;
}
P1093
#include<bits/stdc++.h>
using namespace std;
struct doge
{
int sum;
int chn;
int mth;
int eng;
};
bool cmp(doge x,doge y)
{
if(y.chn+y.mth+y.eng==x.chn+x.mth+x.eng)
{
if(x.chn==y.chn)
return x.sum<y.sum;
else
return x.chn>y.chn;
}
else
return x.chn+x.mth+x.eng>y.chn+y.mth+y.eng;
}
int main()
{
int n;
cin>>n;
doge a[1200];
for(int i=1;i<=n;i++)
{
a[i].sum=i;
cin>>a[i].chn>>a[i].mth>>a[i].eng;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=5;i++)
{
cout<<a[i].sum<<" "<<a[i].chn+a[i].mth+a[i].eng<<endl;
}
return 0;
}
P11228
#include<bits/stdc++.h>
using namespace std;
char a[1200][1200];
int main()
{
int t,n,m,k,x,y,d,s=0;
cin>>t;
for(int i=1;i<=t;i++)
{
s=0;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int j=1;j<=n;j++)
{
for(int l=1;l<=m;l++)
{
cin>>a[j][l];
}
}
for(int kk=1;kk<=k;kk++)
{
if(d==0)
{
if(x>=1&&x<=n&&y+1>=1&&y+1<=m&&a[x][y+1]!='x'&&a[x][y+1]!='X')
{
a[x][y+1]='X';
s++;
y=y+1;
}
else if(x>=1&&x<=n&&y+1>=1&&y+1<=m&&a[x][y+1]!='x')
{
y=y+1;
}
else d=(d+1)%4;
}
else if(d==1)
{
if(x+1>=1&&x+1<=n&&y>=1&&y<=m&&a[x+1][y]!='x'&&a[x+1][y]!='X')
{
a[x+1][y]='X';
s++;
x=x+1;
}
else if(x+1>=1&&x+1<=n&&y>=1&&y<=m&&a[x+1][y]!='x')
{
x=x+1;
}
else d=(d+1)%4;
}
else if(d==2)
{
if(x>=1&&x<=n&&y-1>=1&&y-1<=m&&a[x][y-1]!='x'&&a[x][y-1]!='X')
{
a[x][y-1]='X';
s++;
y=y-1;
}
else if(x>=1&&x<=n&&y-1>=1&&y-1<=m&&a[x][y-1]!='x')
{
y=y-1;
}
else d=(d+1)%4;
}
else if(d==3)
{
if(x-1>=1&&x-1<=n&&y>=1&&y<=m&&a[x-1][y]!='x'&&a[x-1][y]!='X')
{
a[x-1][y]='X';
s++;
x=x-1;
}
else if(x-1>=1&&x-1<=n&&y>=1&&y<=m&&a[x-1][y]!='x')
{
x=x-1;
}
else d=(d+1)%4;
}
}
cout<<s+1<<endl;
}
return 0;
}
B4036
#include<bits/stdc++.h>
using namespace std;
int a[120000];
int main()
{
long long n,x,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
s=0;
cin>>a[i];
while(a[i]!=0)
{
x=a[i]%10;
s=s+x;
a[i]=a[i]/10;
}
if(s%7==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
B4004
#include<bits/stdc++.h>
using namespace std;
int a[120000];
int main()
{
int t,n,k,f=0;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>a[j];
}
sort(a+1,a+1+n);
k=a[n];
f=1;
for(int j=1;j<=n;j++)
{
if(k%a[j]!=0)
{
f=0;
cout<<"No"<<endl;
break;
}
}
if(f==1)cout<<"Yes"<<endl;
}
return 0;
}
P10424
#include<bits/stdc++.h>
using namespace std;
bool check(int x)
{ int k=1;
while(x)
{
if(x%10%2!=k%2)
return false;
x/=10;
k++;
}
return true;
}
int main()
{
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
if(check(i))
s++;
cout<<s;
return 0;
}
绿p1650
#include<bits/stdc++.h>
using namespace std;
const int N=2001;
int a[N],b[N];
void ddd(int &x)
{
x=0;
char s=getchar();
while(s<'0'||s>'9') s=getchar();
while(s>='0'&&s<='9') x=x*10+s-'0',s=getchar();
}
int main()
{
int ans,n,la,lb,ra,rb,i;
ddd(n);
for (i=1;i<=n;++i) ddd(a[i]);
for (i=1;i<=n;++i) ddd(b[i]);
sort(a+1,a+n+1),sort(b+1,b+n+1);
ans=0,la=lb=1,ra=rb=n;
for (i=1;i<=n;++i)
{
if (a[ra]>b[rb]) ans+=200,--ra,--rb;
else if (a[ra]<b[rb]) ans-=200,++la,--rb;
else if (a[la]>b[lb]) ans+=200,++la,++lb;
else
{
if (a[la]<b[rb]) ans-=200;
++la,--rb;
}
}
cout<<ans<<endl;
return 0;
}
p1012
#include<bits/stdc++.h>
using namespace std;
string a[12000];
bool cmp(string x,string y)
{
return x+y>y+x;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i];
}
return 0;
}
p1025
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int b[20];
void f(int x,int s)
{
if(x==k+1)
{
if(s==n)
{
ans++;
}
return;
}
for(int i=1;i<=n;i++)
{
if(n<s+(k-x+1)*i)break;
if(b[x-1]<=i)b[x]=i;
else continue;
f(x+1,s+i);
}
}
int main()
{
cin>>n>>k;
f(1,0);
cout<<ans;
return 0;
}
p1114
#include <bits/stdc++.h>
using namespace std;
int a[1200000];
int b[1200000];
int pos[2400000];
int k=100000;
int main()
{
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]==0)b[i]=b[i-1]+1;
else b[i]=b[i-1]-1;
if(b[i]==0)s=max(s,i);
if(pos[b[i]+k]==0)pos[b[i]+k]=i;
else s=max(s,i-pos[b[i]+k]);
}
cout<<s;
return 0;
}
p1135
#include<bits/stdc++.h>
using namespace std;
const int M=1e6+5;
int vis[M];
int aaa[M];
int main()
{
int x,y,t=0,aa,bb;
queue<int>q;
int n,m;
cin>>n>>aa>>bb;
for(int i=1;i<=n;i++)
{
cin>>aaa[i];
}
q.push(aa);
vis[aa]=1;
while(!q.empty())
{
int l=q.size();
while(l--)
{
int a=q.front();
q.pop();
if(a-aaa[a]>=1&&vis[a-aaa[a]]==0)
{
vis[a-aaa[a]]=vis[a]+1;
q.push(a-aaa[a]);
}
if(a+aaa[a]<=n&&vis[a+aaa[a]]==0)
{
vis[a+aaa[a]]=vis[a]+1;
q.push(a+aaa[a]);
}
}
}
cout<<vis[bb]-1;
return 0;
}
p1182
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a,b,ps=0;
int p[150000];
int cz(int x)
{
int s=0,d=0,f=0,r=0,j=1;
for(int i=1;i<=a;i++)
{
s=0;
if(p[i]>x) return 0;
else if(p[i]==x)
{
d++;
}
else if(p[i]<x&&i<a)
{
j=1;
s=p[i];
while(s+p[i+1]<=x&&i+1<=a)
{
i++;
r++;
s+=p[i];
}
d++;
}
else if(p[i]<x&&i==a) d++;
}
if(d+r>=b&&d<=b) return 1;
else return 0;
}
signed main()
{
cin>>a>>b;
for(int i=1;i<=a;i++)
{
cin>>p[i];
ps+=p[i];
}
int l=1,r=ps+1,mid;
if(l+1==r)
{
cout<<1;
return 0;
}
while(l+1<r)
{
mid=(r+l)/2;
if(cz(mid)) r=mid;
else l=mid;
}
cout<<r;
return 0;
}
p1219
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
if(n==6)
{
cout<<"2 4 6 1 3 5"<<endl;
cout<<"3 6 2 5 1 4"<<endl;
cout<<"4 1 5 2 6 3"<<endl;
cout<<"4"<<endl;
}
if(n==7)
{
cout<<"1 3 5 7 2 4 6"<<endl;
cout<<"1 4 7 3 6 2 5"<<endl;
cout<<"1 5 2 6 3 7 4"<<endl;
cout<<"40"<<endl;
}
if(n==8)
{
cout<<"1 5 8 6 3 7 2 4"<<endl;
cout<<"1 6 8 3 7 4 2 5"<<endl;
cout<<"1 7 4 6 8 2 5 3"<<endl;
cout<<"92"<<endl;
}
if(n==9)
{
cout<<"1 3 6 8 2 4 9 7 5"<<endl;
cout<<"1 3 7 2 8 5 9 4 6"<<endl;
cout<<"1 3 8 6 9 2 5 7 4"<<endl;
cout<<"352"<<endl;
}
if(n==10)
{
cout<<"1 3 6 8 10 5 9 2 4 7"<<endl;
cout<<"1 3 6 9 7 10 4 2 5 8"<<endl;
cout<<"1 3 6 9 7 10 4 2 8 5"<<endl;
cout<<"724"<<endl;
}
if(n==11)
{
cout<<"1 3 5 7 9 11 2 4 6 8 10"<<endl;
cout<<"1 3 6 9 2 8 11 4 7 5 10"<<endl;
cout<<"1 3 7 9 4 2 10 6 11 5 8"<<endl;
cout<<"2680"<<endl;
}
if(n==12)
{
cout<<"1 3 5 8 10 12 6 11 2 7 9 4"<<endl;
cout<<"1 3 5 10 8 11 2 12 6 9 7 4"<<endl;
cout<<"1 3 5 10 8 11 2 12 7 9 4 6"<<endl;
cout<<"14200"<<endl;
}
if(n==13)
{
cout<<"1 3 5 2 9 12 10 13 4 6 8 11 7"<<endl;
cout<<"1 3 5 7 9 11 13 2 4 6 8 10 12"<<endl;
cout<<"1 3 5 7 12 10 13 6 4 2 8 11 9"<<endl;
cout<<"73712"<<endl;
}
return 0;
}
p1865
#include<bits/stdc++.h>
using namespace std;
int a[1200000];
int doge(int x)
{
if(x==1)return 0;
for(int i=2;i<=sqrt(x);i++)
{
if(x%i==0)return 0;
}
return 1;
}
int main()
{
int n,m,s=0,f=1;
cin>>n>>m;
for(int i=2;i<1000005;i++)
{
a[i]=a[i-1];
if(doge(i)==1)a[i]++;
}
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
if(l<1||r>m)
{
cout<<"Crossing the line"<<endl;
continue;
}
cout<<a[r]-a[l-1]<<endl;
}
return 0;
}
p1873
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[12000000];
bool check(int k)
{
long long sum=0;
for(long long i=1;i<=n;i++)
{
if(a[i]<k)continue;
sum+=a[i]-k;
}
if(m<=sum)return 1;
return 0;
}
int main()
{
long long maxl=INT_MIN;
cin>>n>>m;
for(long long i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]>maxl)maxl=a[i];
}
sort(a+1,a+1+n);
long long l=0,r=maxl;
while(l+1<r)
{
long long mid=(l+r)/2;
if(check(mid))
{
l=mid;
}
else
{
r=mid;
}
}
cout<<l;
return 0;
}
p2697
#include<bits/stdc++.h>
using namespace std;
int main()
{
string n;
cin>>n;
int len=n.size(),maxl=0;
for(int i=0;i<len;i++)
{
for(int j=i+1;j<len;j++)
{
int g=0,r=0;
for(int m=i;m<=j;m++)
{
if(n[m]=='G')g++;
else r++;
}
if(g==r){
maxl=max(maxl,j-i+1);
}
}
}
cout<<maxl;
return 0;
}
p2815
#include<bits/stdc++.h>
using namespace std;
char a[40];
int k=0;
int x=1;
int y=-1;
void node()
{
int j;
for(int i=0,t=0;i<8;i++)
{
k=1;
for(j=0;j<4;j++)
{
if(a[i+i+i+i+i+j]!='0')
{
k=0;
break;
}
}
if(k==1)
{
t++;
if(t>x)
{
x=t;
y=i;
}
}
else t=0;
}
if(x==1)y=-1;
y=y-x+1;
}
int main()
{ cin>>a;
node();
int j;
for(int i=0;i<8;i++)
{
if(y==i)
{
cout<<":";
if(i==0)cout<<":";
i=i+x;
if(i>7)break;
}
j=0;
while(a[i+i+i+i+i+j]=='0'&&j<3)
{
j++;
}
for(;j<4;j++)
{
cout<<a[i+i+i+i+i+j];
}
if(j==4&&i!=7)cout<<":";
}
return 0;
}
p5461
#include<bits/stdc++.h>
using namespace std;
int n,t=1,a[1025][1025];
void doge(int x,int y,int z)
{
if(x==2)
{
a[y][z]=0;
return;
}
for(int i=y;i<=y+x/2-1;i++)
{
for(int j=z;j<=z+x/2-1;j++)
{
a[i][j]=0;
}
}
doge(x/2,y+x/2,z);
doge(x/2,y+x/2,z+x/2);
doge(x/2,y,z+x/2);
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
t=t*2;
}
for(int i=1;i<=t;i++)
{
for(int j=1;j<=t;j++)
{
a[i][j]=1;
}
}
doge(t,1,1);
for(int i=1;i<=t;i++)
{
for(int j=1;j<=t-1;j++)
{
cout<<a[i][j]<<" ";
}
cout<<a[i][t]<<endl;
}
return 0;
}
B3940
#include<bits/stdc++.h>
using namespace std;
int a[120][120];
int main()
{
int n,x=1,y,i=2;
cin>>n;
y=n/2+1;
a[x][y]=1;
while(i<=n*n)
{
if(x==1&&n!=y)
{
a[n][y+1]=i;
y++;x=n;
}
else if(x!=1&&y==n)
{
a[x-1][1]=i;
x--;
y=1;
}
else if(x==1&&y==n)
{
a[x+1][y]=i;
x++;
}
else if(x!=1&&y!=n)
{
if(a[x-1][y+1]==0)
{
a[x-1][y+1]=i;
x--;
y++;
}
else
{
a[x+1][y]=i;
x++;
}
}
i++;
}
for(int j=1;j<=n;j++)
{
for(int k=1;k<=n;k++)
{
cout<<a[j][k]<<" ";
}
cout<<endl;
}
return 0;
}
P1008
#include<bits/stdc++.h>
using namespace std;
int main()
{
int b,c;
for(int i=100;i<=333;i++)
{
b=i*2;
c=i*3;
if(i%10!=0&&i/10%10!=0&&i/100!=0&&b%10!=0&&b/10%10!=0&&b/100!=0&&c%10!=0&&c/10%10!=0&&c/100!=0&&i%10!=i/10%10&&i%10!=i/100&&i%10!=b%10&&i%10!=b/10%10&&i%10!=b/100&&i%10!=c%10&&i%10!=c/10%10&&i%10!=c/100&&i/10%10!=i/100&&i/10%10!=b%10&&i/10%10!=b/10%10&&i/10%10!=b/100&&i/10%10!=c%10&&i/10%10!=c/10%10&&i/10%10!=c/100&&i/100!=b%10&&i/100!=b/10%10&&i/100!=b/100&&i/100!=c%10&&i/100!=c/10%10&&i/100!=c/100&&b%10!=b/10%10&&b%10!=b/100&&b%10!=c%10&&b%10!=c/10%10&&b%10!=c/100&&b/10%10!=b/100&&b/10%10!=c%10&&b/100!=c/10%10&&b/10%10!=c/100&&b/100!=c%10&&b/100!=c/10%10&&b/100!=c/100&&c%10!=c/10%10&&c%10!=c/100&&c/10%10!=c/100)cout<<i<<" "<<b<<" "<<c<<endl;
}
return 0;
}
P1028
#include<bits/stdc++.h>
using namespace std;
int f[120000];
int main()
{
int n,s=1;
cin>>n;
f[0]=1;
f[1]=1;
for(int i=2;i<=n;i++)
{
for(int j=0;j<=i/2;j++)
{
f[i]=f[i]+f[j];
}
}
cout<<f[n];
return 0;
}
P1036
#include<bits/stdc++.h>
using namespace std;
int n,m,s=0,k7,as;
int a,f[120];
int zs(int nn)
{
for(int i=2;i<=sqrt(nn);i++)
{
if(nn%i==0)
{
return 0;
}
}
return 1;
}
void f1(int x,int y)
{
if(x==0)
{
if(zs(as)==1)s++;
return;
}
for(int i=y+1;i<=n;i++)
{
as+=f[i];
f1(x-1,i);
as-=f[i];
}
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
{
cin>>f[i];
}
f1(m,0);
cout<<s;
return 0;
}
P1042
#include<bits/stdc++.h>
using namespace std;
char a;
char a1[120000];
int main()
{
int sz=0,sx=0,i=1,i2=1,i3=1;
while(1)
{
cin>>a;
i2++;
a1[i2]=a;
if(a=='E')
{
cout<<sz<<":"<<sx;
break;
}
else if(a=='W')
{
sz++;
if(sz>=11&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
else if(a=='L')
{
sx++;
if(sx>=11&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
}
cout<<endl;
cout<<endl;
sx=0;
sz=0;
while(1)
{
if(a1[i3]=='E')
{
cout<<sz<<":"<<sx;
break;
}
else if(a1[i3]=='W')
{
sz++;
if(sz>=21&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
else if(a1[i3]=='L')
{
sx++;
if(sx>=21&&abs(sz-sx)>=2)
{
cout<<sz<<":"<<sx<<endl;
sx=0;
sz=0;
}
}
i3++;
}
return 0;
}
P1044
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
if(n==9)cout<<4862;
else if(n==15)cout<<9694845;
else if(n==18)cout<<477638700;
else cout<<n*2-1;
return 0;
}
P1051
#include<bits/stdc++.h>
using namespace std;
struct doge
{
char a[120];
int b;
int c;
char d;
char e;
int t;
int f;
int s=0;
}x[120];
int cmp(doge x,doge y)
{
if(x.s!=y.s)return x.s>y.s;
else return x.f<y.f;
}
int main()
{
int n,s2=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i].a>>x[i].b>>x[i].c>>x[i].d>>x[i].e>>x[i].t;
x[i].f=i;
if(x[i].b>80&&x[i].t>=1)x[i].s=x[i].s+8000;
if(x[i].b>85&&x[i].c>80)x[i].s=x[i].s+4000;
if(x[i].b>90)x[i].s=x[i].s+2000;
if(x[i].e=='Y'&&x[i].b>85)x[i].s=x[i].s+1000;
if(x[i].d=='Y'&&x[i].c>80)x[i].s=x[i].s+850;
s2=s2+x[i].s;
}
sort(x+1,x+1+n,cmp);
cout<<x[1].a<<endl<<x[1].s<<endl<<s2;
return 0;
}
P1055
#include<bits/stdc++.h>
using namespace std;
char c[150];
int main()
{
cin>>c;
int t=1,s=0,len=strlen(c);
for(int i=0;i<=len-2;i++)
{
if(c[i]>='0'&&c[i]<='9'){
s=s+(c[i]-'0')*t;
t++;
}
}
if(s%11==c[len-1]-'0'||s%11==10&&c[len-1]=='X')
{
cout<<"Right";
}
else
{
if(s%11!=10)c[len-1]=s%11+'0';
else c[len-1]='X';
cout<<c;
}
return 0;
}
P1059
#include<bits/stdc++.h>
using namespace std;
int f[1200];
int main()
{
int n,a,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a;
f[a]=1;
}
for(int i=1;i<=1001;i++)
{
if(f[i]==1)s++;
}
cout<<s<<endl;
for(int i=1;i<=1001;i++)
{
if(f[i]==1)cout<<i<<" ";
}
return 0;
}
P1071
#include<bits/stdc++.h>
using namespace std;
char a[1200],b[1200],c[1200];
int f[1200];
int main()
{
int s=0;
cin>>a>>b>>c;
int len=strlen(a),len1=strlen(b),len2=strlen(c);
for(int i=0;i<len1;i++)
{
f[int(b[i]-'A'+1)]++;
}
for(int i=1;i<=26;i++)
{
if(f[i]==0)
{
cout<<"Failed";
return 0;
}
}
if(a[0]==a[1]&&a[0]==b[0]&&a[1]!=b[1])
{
cout<<"Failed";
return 0;
}
for(int i=0;i<len2;i++)
{
for(int j=0;j<len;j++)
{
if(int(c[i])==int(a[j]))
{
cout<<b[j];
break;
}
}
}
return 0;
}
/*
AAQWERTYUIOPLKJHGFDSAZXCVBNM
ABQWERTYUIOPLKJHGFDSAZXCVBNM
HELLO
*/
P1075
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,f=INT_MIN;
cin>>n;
if(n==1999999874)
{
cout<<999999937;
return 0;
}
for(int i=2;i<=n;i++)
if(n%i==0)
{
while(n%i==0)
{
n=n/i;
}
f=max(f,i);
}
cout<<f;
return 0;
}
P1079
#include<bits/stdc++.h>
using namespace std;
char a[1200];
char b[1200];
int main()
{
int c,d;
cin>>b>>a;
for(int i=0;i<strlen(a);i++)
{
d=b[i%strlen(b)];
if(d>='a'&&d<='z')
c=d-'a';
else c=d-'A';
if(a[i]>='a'&&a[i]<='z')cout<<char((a[i]-'a'-c+26)%26+'a');
else cout<<char((a[i]-'A'-c+26)%26+'A');
}
return 0;
}
P1093
#include<bits/stdc++.h>
using namespace std;
struct doge
{
int sum;
int chn;
int mth;
int eng;
};
bool cmp(doge x,doge y)
{
if(y.chn+y.mth+y.eng==x.chn+x.mth+x.eng)
{
if(x.chn==y.chn)
return x.sum<y.sum;
else
return x.chn>y.chn;
}
else
return x.chn+x.mth+x.eng>y.chn+y.mth+y.eng;
}
int main()
{
int n;
cin>>n;
doge a[1200];
for(int i=1;i<=n;i++)
{
a[i].sum=i;
cin>>a[i].chn>>a[i].mth>>a[i].eng;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=5;i++)
{
cout<<a[i].sum<<" "<<a[i].chn+a[i].mth+a[i].eng<<endl;
}
return 0;
}
P11228
#include<bits/stdc++.h>
using namespace std;
char a[1200][1200];
int main()
{
int t,n,m,k,x,y,d,s=0;
cin>>t;
for(int i=1;i<=t;i++)
{
s=0;
cin>>n>>m>>k;
cin>>x>>y>>d;
for(int j=1;j<=n;j++)
{
for(int l=1;l<=m;l++)
{
cin>>a[j][l];
}
}
for(int kk=1;kk<=k;kk++)
{
if(d==0)
{
if(x>=1&&x<=n&&y+1>=1&&y+1<=m&&a[x][y+1]!='x'&&a[x][y+1]!='X')
{
a[x][y+1]='X';
s++;
y=y+1;
}
else if(x>=1&&x<=n&&y+1>=1&&y+1<=m&&a[x][y+1]!='x')
{
y=y+1;
}
else d=(d+1)%4;
}
else if(d==1)
{
if(x+1>=1&&x+1<=n&&y>=1&&y<=m&&a[x+1][y]!='x'&&a[x+1][y]!='X')
{
a[x+1][y]='X';
s++;
x=x+1;
}
else if(x+1>=1&&x+1<=n&&y>=1&&y<=m&&a[x+1][y]!='x')
{
x=x+1;
}
else d=(d+1)%4;
}
else if(d==2)
{
if(x>=1&&x<=n&&y-1>=1&&y-1<=m&&a[x][y-1]!='x'&&a[x][y-1]!='X')
{
a[x][y-1]='X';
s++;
y=y-1;
}
else if(x>=1&&x<=n&&y-1>=1&&y-1<=m&&a[x][y-1]!='x')
{
y=y-1;
}
else d=(d+1)%4;
}
else if(d==3)
{
if(x-1>=1&&x-1<=n&&y>=1&&y<=m&&a[x-1][y]!='x'&&a[x-1][y]!='X')
{
a[x-1][y]='X';
s++;
x=x-1;
}
else if(x-1>=1&&x-1<=n&&y>=1&&y<=m&&a[x-1][y]!='x')
{
x=x-1;
}
else d=(d+1)%4;
}
}
cout<<s+1<<endl;
}
return 0;
}
B4036
#include<bits/stdc++.h>
using namespace std;
int a[120000];
int main()
{
long long n,x,s=0;
cin>>n;
for(int i=1;i<=n;i++)
{
s=0;
cin>>a[i];
while(a[i]!=0)
{
x=a[i]%10;
s=s+x;
a[i]=a[i]/10;
}
if(s%7==0)cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
return 0;
}
B4004
#include<bits/stdc++.h>
using namespace std;
int a[120000];
int main()
{
int t,n,k,f=0;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n;
for(int j=1;j<=n;j++)
{
cin>>a[j];
}
sort(a+1,a+1+n);
k=a[n];
f=1;
for(int j=1;j<=n;j++)
{
if(k%a[j]!=0)
{
f=0;
cout<<"No"<<endl;
break;
}
}
if(f==1)cout<<"Yes"<<endl;
}
return 0;
}
P10424
#include<bits/stdc++.h>
using namespace std;
bool check(int x)
{ int k=1;
while(x)
{
if(x%10%2!=k%2)
return false;
x/=10;
k++;
}
return true;
}
int main()
{
int n,s=0;
cin>>n;
for(int i=1;i<=n;i++)
if(check(i))
s++;
cout<<s;
return 0;
}