A: Determine the bear elephant. There are four of the six parameters, which are legs and must be the same. If the other two are the same, they are bears. If they do not meet the requirements, they are stars!
B: Give a few numbers and arrange them in a descending manner. If there are three or more sorting methods, output yes, and then output any three sorting methods (serial number) with SPJ.
C: There are n cards to build a house and ask how many layers can be built.
Let's take a picture! It means you can't understand how to build it? Go hitting me! (To hit me ?)
I have a table of less than 20: 01001,01101, 10111,11111. If there is no such table, do not ask me why.
D: give a large wall (slightly uneven height), and then splice it with a small wall!
For example, the answer is 2, and you can check the code without asking me why.
E: no questions.
Question:
A, B: omitted,
C: enumerate each layer to see if it can be obtained. In my code, for each loop is a layer, and FR indicates the current layer.
D: preprocessing + KMP. It's time to get rid of the code. You just need to judge M = 1. The others are normal bare KMP.
E: 233.
Code: It is ABCD in order. If you try to find an example and run it again, you will know the question and question.
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int f[10],num[10];int main(){// freopen("test.in","r",stdin); int i,j,k,flag=0; for(i=1;i<=6;i++)scanf("%d",&f[i]); sort(f+1,f+7); for(i=1;i<=6;i++) { if(f[i]==f[i-1]) { num[i]=num[i-1]; } num[i]++; if(num[i]==4) { flag=1; for(j=0;j<4;j++) { f[i-j]=0; } } } if(!flag) { printf("Alien\n"); return 0; } else { sort(f+1,f+7); if(f[5]==f[6]) { puts("Elephant"); } else puts("Bear"); } return 0;}
#include <cstdio>#include <cstring>#include <algorithm>#define N 2005using namespace std;struct KSD{ int x,f; bool operator < (const KSD& a)const { return x<a.x; }}s[N];struct Syndra{ int v,next;}e[N];int head[N],cnt,num[N],visit[N];int n,ans,m;void add(int u,int v){ cnt++; e[cnt].v=v; e[cnt].next=head[u]; head[u]=cnt;}int pre[N];int ppp[N],star;void print(int x,int p){ int flag=0; if(x>m) { ans++; for(star=n;p;p=pre[p])ppp[star--]=s[p].f; for(star=1;star<=n;star++)printf("%d ",ppp[star]); puts(""); if(ans==3)exit(0); return ; } int i,v; for(i=head[x];i;i=e[i].next) { v=e[i].v; if(!visit[v]) { flag=1; visit[v]=1; pre[v]=p; print(x,v); visit[v]=0; } } if(!flag)print(x+1,p);}int main(){ int i,j,k,flag=0; scanf("%d",&n); for(i=1;i<=n;i++)scanf("%d",&s[i].x),s[i].f=i; sort(s+1,s+n+1); for(i=1;i<=n;i++) { if(s[i].x!=s[i-1].x)num[++m]=1; else num[m]++; if(num[m]>=3)flag+=2; if(num[m]==2)flag++; add(m,i); } if(flag<2) { puts("NO"); return 0; } else { puts("YES"); print(1,0); } return 0;}
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>using namespace std;long long n,sum,now,ans,fr;int main(){ long long i,j,k; cin>>n; for(sum=now=2;sum<=n;now+=3,sum+=now) { fr++; if((n+fr)%3==0)ans++; } cout<<ans; return 0;}
#include <cstdio>#include <cstring>#include <algorithm>#define N 201000using namespace std;int fix,a[N],pre[N],n,m,s[N],ans;int main(){// freopen("test.in","r",stdin); int i,j,k,x,y; scanf("%d%d",&n,&m); if (m == 1) { printf("%d\n", n); return 0; } if (n < m) { printf("0"); return 0; } scanf("%d",&x); for(i=1;i<n;i++) { scanf("%d",&y); a[i]=y-x;x=y; }n--; scanf("%d",&x); for(i=1;i<m;i++) { scanf("%d",&y); s[i]=y-x;x=y; }m--; s[m + 1] = 1 << 30; for(fix=0,i=2;i<=m;i++) { while(fix&&s[fix+1]!=s[i])fix=pre[fix]; if(s[fix+1]==s[i])fix++; pre[i]=fix; } for(fix=0,i=1;i<=n;i++) { while(fix&&s[fix+1]!=a[i])fix=pre[fix]; if(s[fix+1]==a[i])fix++; if(fix==m)ans++; } printf("%d\n",ans); return 0;}
Okay, actually, I am here to post code, and I am not writing well to solve the problem.
Unhappy? Come and hit me ?!!
Copy the Translation results to Google
[Codeforces] round #269 ABCD