NOIP 2017 时间复杂度 (模拟)
生活随笔
收集整理的這篇文章主要介紹了
NOIP 2017 时间复杂度 (模拟)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目大意:略
傻了吧唧的我wa了好幾次
我的模擬功底真的不咋地
linux下用gets會報錯,我用的fgets
1 #include <string> 2 #include "stdio.h" 3 #include <cstring> 4 #include <iostream> 5 #include <algorithm> 6 #define ll long long 7 #define N 1010 8 #define rint register int 9 #define ll long long 10 #define il inline 11 #define idx(x) (x-'a'+1) 12 #define idg(x) (x-'0') 13 using namespace std; 14 //re 15 int T,n,cnt,j; 16 int use[30]; 17 char str[110][20]; 18 inline bool isdig(char c) 19 {return ('0'<=c&&c<='9')?1:0;} 20 int dfs() 21 { 22 int ans=0,now=j,val=0,cal=0; 23 if(str[j][0]=='E') return -1; 24 if(str[j][0]=='F') 25 { 26 if(use[idx(str[j][2])]) 27 return -1; 28 use[idx(str[j][2])]=1; 29 while(str[j+1][0]=='F') 30 { 31 j++,cal=dfs(); 32 if(cal==-1) return -1; 33 ans=max(ans,cal); 34 } 35 int k=4; 36 while(isdig(str[now][k])) 37 val=val*10+idg(str[now][k]),k++; 38 k++; 39 if(str[now][4]=='n'){ 40 if(str[now][6]!='n') ans=0; 41 }else if(!isdig(str[now][k])){ 42 ans++; 43 }else{ 44 int w=0; 45 while(isdig(str[now][k])) 46 w=w*10+idg(str[now][k]),k++; 47 if(val>w) ans=0; 48 } 49 } 50 use[idx(str[now][2])]=0; 51 j++; 52 if(str[j][0]!='E') return -1; 53 else return ans; 54 } 55 56 int main() 57 { 58 //freopen("complexity6.in","r",stdin); 59 scanf("%d",&T); 60 for(int t=1;t<=T;t++) 61 { 62 int q=0; 63 scanf("%d",&n); 64 memset(str,0,sizeof(str)); 65 memset(use,0,sizeof(use)); 66 scanf("%s\n",str[0]); 67 for(int i=1;i<=n;i++) 68 fgets(str[i],20,stdin); 69 int ret=0,ans=0;j=1; 70 for(;j<=n;j++){ 71 ans=dfs(); 72 if(ans==-1){ret=-1;printf("ERR\n");break;} 73 else {ret=max(ret,ans);} 74 } 75 if(ret==-1) continue; 76 int k=0,flag=0; 77 while(1){ 78 if(str[0][k]=='n') flag=1; 79 if(!isdig(str[0][k])) 80 {k++;continue;} 81 while(isdig(str[0][k])) 82 q=q*10+idg(str[0][k]),k++; 83 break; 84 } 85 if(flag==0) q=0; 86 if(ret==q) printf("Yes\n"); 87 else printf("No\n"); 88 } 89 return 0; 90 }?
轉載于:https://www.cnblogs.com/guapisolo/p/9734137.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的NOIP 2017 时间复杂度 (模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: springboot(七) 配置嵌入式S
- 下一篇: Javascript继承4:洁净的继承者