题目链接:http://uoj.ac/problem/123
又开提答坑啦,要不是一定要讲题谁他妈要这样伤害自己
CASE 1,2
首先可以打一个通用暴力,用于模拟操作过程,对于每一个操作随机一个选择,然后跑多次记录答案。
1 #include<iostream> 2 #include<cstdio> 3 #include<algorithm> 4 #include<vector> 5 #include<cstdlib> 6 #include<cmath> 7 #include<cstring> 8 #include<string> 9 #include<ctime> 10 using namespace std; 11 #define maxn 1000010 12 #define llg long long 13 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); 14 llg n,m,dl[maxn],tail,anst,ans[maxn],val[maxn],maxl,cs; 15 llg T=1; 16 char ch,s[maxn]; 17 18 llg next_x(llg x){x++; while (s[x]==' ') x++; return x;} 19 20 struct node 21 { 22 llg type; 23 llg t1,v1,t2,v2,fu,to1,to2; 24 }a[maxn]; 25 26 llg make_number(llg &x) 27 { 28 llg val=0,p=1; 29 if (s[x]=='-') x++,p=-1; 30 while (s[x]>='0' && s[x]<='9') 31 { 32 val*=10; 33 val+=s[x]-'0'; 34 x++; 35 } 36 return val*p; 37 } 38 39 void Decompression_(llg i) 40 { 41 42 llg x=1; 43 if (s[x]=='v') 44 { 45 a[i].type=1; 46 x=next_x(x); 47 a[i].v1=make_number(x); 48 x=next_x(x); 49 if (s[x]=='+') a[i].fu=1;else a[i].fu=-1; 50 x=next_x(x); 51 if (s[x]=='c') a[i].t2=0; else a[i].t2=1; 52 x=next_x(x); 53 a[i].v2=make_number(x); 54 } 55 if (s[x]=='s') 56 { 57 a[i].type=2; 58 x=next_x(x); 59 a[i].to1=make_number(x); 60 x=next_x(x); 61 a[i].to2=make_number(x); 62 } 63 if (s[x]=='i') 64 { 65 a[i].type=3; 66 x=next_x(x); 67 if (s[x]=='c') a[i].t1=0; else a[i].t1=1; 68 x=next_x(x); 69 a[i].v1=make_number(x); 70 x=next_x(x); 71 if (s[x]=='c') a[i].t2=0; else a[i].t2=1; 72 x=next_x(x); 73 a[i].v2=make_number(x); 74 x=next_x(x); 75 a[i].to1=make_number(x); 76 x=next_x(x); 77 a[i].to2=make_number(x); 78 } 79 } 80 81 bool pd(char ch) 82 { 83 if (ch>='0' && ch<='9') return 1; 84 if (ch=='v' || ch=='i' || ch=='+' || ch=='-' || ch=='s' || ch=='c' || ch==' ') return 1; 85 return 0; 86 } 87 88 void init() 89 { 90 cin>>n>>m; 91 ch=getchar(); 92 for (llg i=1;i<=n;i++) 93 { 94 llg len=0; 95 ch=getchar(); 96 while (pd(ch)) {s[++len]=ch; ch=getchar();} 97 Decompression_(i); 98 for (llg i=0;i<=len+1;i++) s[i]='