这场比赛跟个zz一样 div1卡在了同余方程上 心态崩了去做div2 然后被T1搞崩了

T1:

大模拟

比较像配平方程式

思路:

但是未知物质每种元素系数不能≥10 且不能为空 (如CO2+?=CO2)

没考虑以上两种情况调了好久也没对 心态爆炸

loj 6255

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<cstdlib>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<vector>
 8 #include<queue>
 9 #define inf 2139062143
10 #define ll long long
11 #define MAXN 700
12 using namespace std;
13 inline int read()
14 {
15     int x=0,f=1;char ch=getchar();
16     while(!isdigit(ch)) {if(ch=='-') f=-1;ch=getchar();}
17     while(isdigit(ch)) {x=x*10+ch-'0';ch=getchar();}
18     return x*f;
19 }
20 int n,m,len,i,hsh[2][30];
21 bool f,k;
22 char str[MAXN];
23 int main()
24 {
25     n=read(),m=read();
26     while(n--)
27     {
28         k=0;
29         memset(hsh,0,sizeof(hsh));
30         scanf("%s",str+1);
31         len=strlen(str+1);
32         for(i=1;i<=len;i++)
33         {
34             if(str[i]=='=') break;
35             if('A'<=str[i]&&str[i]<='Z')
36             {
37                 if(isdigit(str[i+1])) hsh[0][str[i]-'A']+=(str[i+1]-'0');
38                 else hsh[0][str[i]-'A']++;
39             }
40             else {if(str[i]=='?') f=0;continue;}
41         }
42         i++;
43         //cout<<i<<" "<<len;
44         for(i;i<=len;i++)
45         {
46             //cout<<i<<endl;
47             if('A'<=str[i]&&str[i]<='Z')
48             {
49                 //cout<<i<<endl;
50                 if(isdigit(str[i+1])) hsh[1][str[i]-'A']+=(str[i+1]-'0');
51                 else hsh[1][str[i]-'A']++;
52             }
53             else {if(str[i]=='?') f=1;continue;}
54         }
55         for(int i=0;i<26;i++) {if(hsh[f][i]>hsh[f^1][i]||hsh[f^1][i]-hsh[f][i]>9) {puts("No Solution");goto ed;}}
56         for(int i=0;i<26;i++)
57         {
58             if(hsh[f^1][i]-hsh[f][i]==1) {printf("%c",i+'A');k=1;}
59             else if(hsh[f^1][i]-hsh[f][i]) {printf("%c%d",i+'A',hsh[f^1][i]-hsh[f][i]);k=1;}
60         }
61         if(!k) printf("No Solution");
62         printf("\n");
63         ed:;
64     }
65 }
View Code

相关文章: