2018 ACM 网络选拔赛 沈阳赛区
Posted cmyg
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2018 ACM 网络选拔赛 沈阳赛区相关的知识,希望对你有一定的参考价值。
B. Call of Accepted
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e2+10; 25 26 /** 27 + - 3 28 * / 2 29 d 1 30 ( ) 0 31 **/ 32 33 int xl[maxn],xr[maxn],y[maxn]; 34 char s[maxn],z[maxn]; 35 36 int main() 37 { 38 int len,i,g1,g2,a,b,c,d,sym; 39 while (~scanf("%s",s)) 40 { 41 len=strlen(s); 42 g1=0; 43 g2=0; 44 y[0]=inf; 45 for (i=0;i<len;i++) 46 if (s[i]>=‘0‘ && s[i]<=‘9‘) 47 { 48 g1++; 49 xl[g1]=0; 50 while (s[i]>=‘0‘ && s[i]<=‘9‘) 51 { 52 xl[g1]=xl[g1]*10+s[i]-48; 53 i++; 54 } 55 i--; 56 xr[g1]=xl[g1]; 57 } 58 else 59 { 60 switch(s[i]) 61 { 62 case ‘(‘: 63 sym=0; 64 break; 65 case ‘)‘: 66 sym=0; 67 break; 68 case ‘d‘: 69 sym=1; 70 break; 71 case ‘*‘: 72 sym=2; 73 break; 74 case ‘/‘: 75 sym=2; 76 break; 77 case ‘+‘: 78 sym=3; 79 break; 80 case ‘-‘: 81 sym=3; 82 break; 83 } 84 while (y[g2]<=sym || s[i]==‘)‘) 85 { 86 switch(z[g2]) 87 { 88 case ‘d‘: 89 ///ldr l>=0,r>=1,else illegal 90 ///正数,负数 91 xl[g1-1]=max(0,xl[g1-1]); 92 xl[g1]=max(1,xl[g1]); 93 xr[g1-1]*=xr[g1]; 94 break; 95 case ‘+‘: 96 xl[g1-1]+=xl[g1]; 97 xr[g1-1]+=xr[g1]; 98 break; 99 case ‘-‘: 100 xl[g1-1]-=xr[g1]; 101 xr[g1-1]-=xl[g1]; 102 break; 103 case ‘*‘: 104 a=xl[g1-1]*xl[g1]; 105 b=xl[g1-1]*xr[g1]; 106 c=xr[g1-1]*xl[g1]; 107 d=xr[g1-1]*xr[g1]; 108 xl[g1-1]=min(min(a,b),min(c,d)); 109 xr[g1-1]=max(max(a,b),max(c,d)); 110 break; 111 case ‘/‘: 112 a=xl[g1-1]/xl[g1]; 113 b=xl[g1-1]/xr[g1]; 114 c=xr[g1-1]/xl[g1]; 115 d=xr[g1-1]/xr[g1]; 116 xl[g1-1]=min(min(a,b),min(c,d)); 117 xr[g1-1]=max(max(a,b),max(c,d)); 118 break; 119 case ‘(‘: 120 break; 121 } 122 if (z[g2]==‘(‘) 123 break; 124 g2--; 125 g1--; 126 } 127 if (s[i]==‘)‘) 128 g2--; 129 else 130 { 131 y[++g2]=sym; 132 z[g2]=s[i]; 133 } 134 } 135 136 while (g2!=0) 137 { 138 switch(z[g2]) 139 { 140 case ‘d‘: 141 xr[g1-1]*=xr[g1]; 142 break; 143 case ‘+‘: 144 xl[g1-1]+=xl[g1]; 145 xr[g1-1]+=xr[g1]; 146 break; 147 case ‘-‘: 148 xl[g1-1]-=xr[g1]; 149 xr[g1-1]-=xl[g1]; 150 break; 151 case ‘*‘: 152 a=xl[g1-1]*xl[g1]; 153 b=xl[g1-1]*xr[g1]; 154 c=xr[g1-1]*xl[g1]; 155 d=xr[g1-1]*xr[g1]; 156 xl[g1-1]=min(min(a,b),min(c,d)); 157 xr[g1-1]=max(max(a,b),max(c,d)); 158 break; 159 case ‘/‘: 160 a=xl[g1-1]/xl[g1]; 161 b=xl[g1-1]/xr[g1]; 162 c=xr[g1-1]/xl[g1]; 163 d=xr[g1-1]/xr[g1]; 164 xl[g1-1]=min(min(a,b),min(c,d)); 165 xr[g1-1]=max(max(a,b),max(c,d)); 166 break; 167 case ‘(‘: 168 break; 169 } 170 g2--; 171 g1--; 172 } 173 174 printf("%d %d ",xl[1],xr[1]); 175 } 176 177 return 0; 178 } 179 /* 180 3*(2d3) 181 1+1d2d3d4d5+2 182 183 (2d3)*(1+3*3d4)d5 184 185 (2+(3*4+5d1d3)d2)d3 186 187 188 189 (10-30)*3d4 190 191 (10-3d4)*2d3 192 193 (10-3d4)*(10-3d4) 194 195 (10-5d5)*(10-5d5) 196 197 3d(10-3d4) 198 3d(10-3d4)d(10-3d4) 199 */
I. Lattice‘s basics in digital electronics
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 int tr[1000000]; 27 char s1[200010*10],s2[200010*10],s3[200010*10],s4[200010*10]; 28 char s[200010*10]; 29 30 int main() 31 { 32 int t,m,n,a,i,j,k,len,now,g,value; 33 scanf("%d",&t); 34 while (t--) 35 { 36 memset(tr,0,sizeof(tr)); 37 scanf("%d%d",&m,&n); 38 for (i=1;i<=n;i++) 39 { 40 scanf("%d%s",&a,s); 41 len=strlen(s); 42 k=1; 43 for (j=0;j<len;j++) 44 k=(k<<1)+s[j]-48; 45 tr[k]=a; 46 } 47 48 scanf("%s",s1); 49 len=strlen(s1); 50 j=0; 51 for (i=0;i<len;i++) 52 { 53 if (s1[i]>=‘0‘ && s1[i]<=‘9‘) 54 value=s1[i]-48; 55 else if (s1[i]>=‘A‘ && s1[i]<=‘F‘) 56 value=s1[i]-55; 57 else 58 value=s1[i]-87; 59 60 s2[j++]=value/8+48; 61 value%=8; 62 s2[j++]=value/4+48; 63 value%=4; 64 s2[j++]=value/2+48; 65 value%=2; 66 s2[j++]=value+48; 67 } 68 s2[j]=‘