2016"百度之星" - 资格赛(Astar Round1)
http://acm.hdu.edu.cn/showproblem.php?pid=5685
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; const int MAXN = 1e5 + 5; int H[MAXN]; char Hstr[MAXN]; int N, l, r; const int mods = 9973; typedef long long LL; LL mod_pow(LL x, LL n, LL mod) { LL res = 1; while(n > 0) { if(n & 1) res = res * x % mod; x = x * x % mod; n >>= 1; } return res; } int main(){ while(~scanf("%d", &N)){ scanf("%s", Hstr); int len = strlen(Hstr); H[0] = 1; for(int i = 1;i <= len;i ++){ H[i] = H[i - 1] * (Hstr[i - 1] - 28) % mods; } while(N --){ scanf("%d%d", &l, &r); if(l > r) swap(l, r); printf("%I64d\n", (LL)H[r] * mod_pow(H[l - 1], mods - 2, mods) % mods); } } return 0; } /* #include <stdio.h> #include <string.h> char str[100010]; int main() { int n,a,b,k,i,j,s,l; while (scanf("%d",&n)!=EOF) { memset(str,0,sizeof(str)); scanf("%s",str); l = strlen(str); //printf("%d\n",l); for (k = 0;k<n;k++) { j = 1; scanf("%d %d",&a,&b); for (i = a-1;i < b;i++) printf("%d,",str[i]); printf("\n"); for (i = a-1;i < b;i++) { j = (str[i]-28) % 9973*j; } j = j % 9973; printf("%d\n",j); } } return 0; } */
http://acm.hdu.edu.cn/showproblem.php?pid=5686
#include <iostream> #include <stdio.h> #include <string.h> using namespace std; int a[205][205]; int main() { memset(a,0,sizeof(a)); a[1][200]=1;a[2][200]=2; int i,j; for(i=3;i<=200;i++) { for(j=200;j>0;j--) { a[i][j]=a[i][j]+a[i-1][j]+a[i-2][j]; if(a[i][j]>9) { a[i][j-1]=a[i][j]/10; a[i][j]=a[i][j]%10; } } } int n; while(cin>>n) { j=0; while(a[n][j]==0)j++; for(;j<=200;j++) { cout<<a[n][j]; } cout<<endl; } return 0; }
http://acm.hdu.edu.cn/showproblem.php?pid=5687
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; #define FIN freopen("input.txt","r", stdin) struct node{ int next[27]; int v,s; void init(){ v=s=0; memset(next,-1,sizeof(next)); } }; struct node L[4000000]; int tot=0; void add(char a[],int len){ int now=0; for(int i=0;i<len;i++){ int tmp=a[i]-'a'; int next=L[now].next[tmp]; if(next==-1){ next=++tot; L[next].init(); L[next].v=-1; L[now].next[tmp]=next; } now=next; L[now].s ++; } L[now].v=0; } bool query(char a[],int len){ int now=0; for(int i=0;i<len;i++){ int tmp=a[i]-'a'; int next=L[now].next[tmp]; if(next==-1)return false; now=next; } return L[now].s > 0; } void deletes(char a[], int len){ int now=0, late; for(int i=0;i<len;i++){ int tmp=a[i]-'a'; int next=L[now].next[tmp]; if(next==-1) return; late = now; now=next; } now = 0; for(int i=0;i<len;i++){ int tmp=a[i]-'a'; int next=L[now].next[tmp]; if(next==-1) return; late = now; now=next; L[now].s --; } L[now].init(); int tmp=a[len - 1]-'a'; L[late].next[tmp] = -1; } char S1[15]; char S2[35]; int N; int main(){ //FIN; L[0].init(); scanf("%d", &N); while(N --){ scanf("%s%s", S1, S2); if(S1[0] == 'i' || S1[0] == 'I') add(S2, strlen(S2)); else if(S1[0] == 's' || S1[0] == 'S'){ bool v = query(S2, strlen(S2)); if(v){ printf("Yes\n"); } else{ printf("No\n"); } } else{ deletes(S2, strlen(S2)); } } return 0; }
http://acm.hdu.edu.cn/showproblem.php?pid=5688
#include <cstdio> #include <cstring> #include <map> #include <string> #include <algorithm> using namespace std; #define FIN freopen("input.txt","r", stdin) int N; char tstr[40 + 5]; map<string, int>TM; int main(){ //FIN; TM.clear(); scanf("%d", &N); for(int i = 0;i < N;i ++){ scanf("%s", tstr); sort(tstr, tstr + strlen(tstr)); if(!TM[string(tstr)]) TM[string(tstr)] = 0; printf("%d\n", TM[string(tstr)]); TM[string(tstr)] ++; } return 0; }