Problem A. Integers Exhibition
找出所有非$233-mogic$数,初始化只有$1$,每次枚举一个素数去暴力它的幂
对这样生成的所有数,从小到大,维护因子数最多的$234$个,如果有$234$个数因子比它多这个数就删掉
最后再统计一遍所有非$0-mogic$到非$233-mogic$数
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const LL MAXN = 1000000000001000000LL; 5 map<LL, LL> mp, cd; 6 map<LL, LL> :: iterator it; 7 priority_queue<LL> pq; 8 vector<LL> v[234]; 9 10 bool pr(int i) { 11 for (int j = 2; j < i; ++j) 12 if (i % j == 0) return false; 13 return true; 14 } 15 16 // BIT 17 int c[103682]; 18 int lowbit(int s) { 19 return s & (-s); 20 } 21 void modify(int i, int x) { 22 while (i < 103682) c[i] += x, i += lowbit(i); 23 return; 24 } 25 int query(int i) { 26 int ret = 0; 27 while (i > 0) ret += c[i], i -= lowbit(i); 28 return ret; 29 } 30 31 int main() { 32 mp[1] = 1; 33 for(int i = 2; i <= 293; ++i) { 34 if(!pr(i)) continue; 35 cd.clear(); 36 for(it = mp.begin(); it != mp.end(); ++it) { 37 LL fi = (*it).first, se = (*it).second, p = 0; 38 cd[fi] = se; 39 for(LL j = fi; j <= MAXN / i; j *= i) { 40 cd[j * i] = se * (++p + 1); 41 } 42 } 43 mp.clear(); 44 while(!pq.empty()) pq.pop(); 45 for(it = cd.begin(); it != cd.end(); ++it) { 46 LL fi = (*it).first, se = (*it).second; 47 if(pq.size() < 234 || -pq.top() <= se) { 48 pq.push(-se); 49 if(pq.size() > 234) pq.pop(); 50 mp[fi] = se; 51 } 52 } 53 } 54 for(it = mp.begin(); it != mp.end(); ++it) { 55 LL fi = (*it).first, se = (*it).second; 56 int x = query(103680 - se); 57 for(int i = x; i <= 233; ++i) v[i].push_back(fi); 58 modify(103681 - se, 1); 59 } 60 int T; 61 scanf("%d", &T); 62 while(T--) { 63 LL N, K; 64 scanf("%lld %lld", &N, &K); 65 LL l = 1, r = MAXN; 66 while(l < r) { 67 LL m = (l + r) / 2; 68 LL o = upper_bound(v[K].begin(), v[K].end(), m) - v[K].begin(); 69 if(m - o >= N) r = m; 70 else l = m + 1; 71 } 72 printf("%lld ", r); 73 } 74 return 0; 75 }
取根号行把每项都打出来,然后每个询问往左上角跳至多根号步,惨遭卡常
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long a[100010],b[100010],c[600][100010],d[100010],e[100010]; 4 long long T,n,m,i,j,k,s,t,x,p1,p2,temp,ans,mod=1e9+7,v; 5 namespace fastIO{ 6 #define BUF_SIZE 100000 7 #define OUT_SIZE 100000 8 #define ll long long 9 //fread->read 10 bool IOerror=0; 11 inline char nc(){ 12 static char buf[BUF_SIZE],*p1=buf+BUF_SIZE,*pend=buf+BUF_SIZE; 13 if (p1==pend){ 14 p1=buf; pend=buf+fread(buf,1,BUF_SIZE,stdin); 15 if (pend==p1){IOerror=1;return -1;} 16 //{printf("IO error! ");system("pause");for (;;);exit(0);} 17 } 18 return *p1++; 19 } 20 inline bool blank(char ch){return ch==' '||ch==' '||ch==' '||ch==' ';} 21 inline void read(long long &x){ 22 bool sign=0; char ch=nc(); x=0; 23 for (;blank(ch);ch=nc()); 24 if (IOerror)return; 25 if (ch=='-')sign=1,ch=nc(); 26 for (;ch>='0'&&ch<='9';ch=nc())x=x*10+ch-'0'; 27 if (sign)x=-x; 28 } 29 #undef ll 30 #undef OUT_SIZE 31 #undef BUF_SIZE 32 }; 33 using namespace fastIO; 34 long long ksm(long long x,long long y,long long mod) 35 { 36 long long temp=1; 37 while (y>0) 38 { 39 if (y%2==1) temp=temp*x%mod; 40 y/=2; 41 x=x*x%mod; 42 } 43 return temp; 44 } 45 int main() 46 { 47 // clock_t startTime,endTime; 48 // startTime = clock(); 49 // freopen("data.txt", "r", stdin); 50 // freopen("ans.txt", "w", stdout); 51 // a fac 52 // b inv_fac 53 // c [.. ,...] 54 // d inv 55 // e pow(2, ) 56 e[0]=d[0]=a[0]=b[0]=1; 57 for (i=1;i<=1e5;i++) 58 { 59 d[i]=ksm(i,mod-2,mod); 60 a[i]=a[i-1]*i%mod; 61 b[i]=b[i-1]*d[i]%mod; 62 e[i]=e[i-1]*2%mod; 63 } 64 // size 65 temp=279; 66 for (i=1;i<=100000/temp;i++) 67 { 68 c[i][0]=1;t=1;s=i*temp; 69 for (j=1;j<=(s+1)/2;j++) 70 { 71 t=t*(s-j+1)%mod; 72 t=t*d[j]%mod; 73 c[i][j]=c[i][j-1]+t; 74 if(c[i][j] >= mod) c[i][j] -= mod; 75 } 76 for (j=(s+1)/2+1;j<s;j++) 77 { 78 c[i][j]=e[s]-c[i][s-j-1]; 79 if(c[i][j] <0) c[i][j] += mod; 80 } 81 c[i][s]=e[s]; 82 } 83 // endTime = clock(); 84 // cout << "Totle Time : " <<(double)(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl; 85 86 87 scanf("%lld", &T); 88 // read(T); 89 while (T--) 90 { 91 scanf("%lld %lld", &n, &m); 92 // read(n);read(m); 93 if (n==m) 94 { 95 printf("%lld ",e[n]); 96 continue; 97 } 98 ans=0;i=n;v=0; 99 while (i%temp!=0&&m>0) 100 { 101 s=a[i-1]*b[m]%mod; 102 s=s*b[i-1-m]%mod; 103 ans=(ans+e[v]*s)%mod; 104 v++; 105 i--;m--; 106 } 107 if (m==0) ans=(ans+e[v])%mod; 108 else 109 { 110 k=i/temp; 111 ans=(ans+c[k][m]*e[v])%mod; 112 } 113 printf("%lld ",ans); 114 } 115 // endTime = clock(); 116 // cout << "Totle Time : " <<(double)(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl; 117 }
感觉没有那么好做阿?
维护每个$1/2$连通块和大小,全$1$连通块和大小,以及全$1$连通块子树中只隔一个$3$的$1/2$连通块大小之和
询问一查询一下$t$所在$1/2$连通块和$s$所在的全$1$连通块是否只隔一条$3$边,是的话必定一个是另一个的父亲
询问二的贡献有三部分,$s$所在的全$1$块大小,$s$所在的子树中只隔一条$3$边的$1/2$块大小之和,若$s$所在全$1$块的父边是$3$还要加上父亲的$1/2$块大小
当$3$变为$2$时,先对两个块的父亲所在全$1$块中删去子树隔一条$3$边的$1/2$块大小贡献,合并两个块再加回去
当$2$变为$1$时,两个全$1$块的子树中只隔一条$3$边的$1/2$块大小贡献也要合并
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 10; 4 typedef pair<int, int> pii; 5 map<pii, int> mp; 6 map<pii, int> :: iterator it; 7 vector<int> G[maxn]; 8 9 int F[maxn], D[maxn], c[maxn]; 10 void dfs(int x, int f, int d) { 11 F[x] = f, D[x] = d; 12 for(int i = 0; i < G[x].size(); ++i) { 13 int to = G[x][i]; 14 if(to == f) continue; 15 dfs(to, x, d + 1); 16 } 17 } 18 19 int fa[2][maxn], r[2][maxn]; 20 int Find(int o, int x) { 21 return fa[o][x] == x ? x : fa[o][x] = Find(o, fa[o][x]); 22 } 23 void Union(int o, int x, int y) { 24 int fu = Find(o, x), fv = Find(o, y); 25 if(D[fu] < D[fv]) swap(fu, fv); 26 if(fu != fv) { 27 fa[o][fu] = fv, r[o][fv] += r[o][fu]; 28 if(o == 0) c[fv] += c[fu]; 29 } 30 } 31 32 int main() { 33 int T; 34 scanf("%d", &T); 35 while(T--) { 36 int n, m; 37 scanf("%d %d", &n, &m); 38 for(int i = 1; i <= n; ++i) fa[0][i] = fa[1][i] = i, r[0][i] = r[1][i] = 1, c[i] = 0, G[i].clear(); 39 mp.clear(); 40 for(int i = 1; i < n; ++i) { 41 int u, v, w; 42 scanf("%d %d %d", &u, &v, &w); 43 G[u].push_back(v), G[v].push_back(u); 44 if(u > v) swap(u, v); 45 mp[pii(u, v)] = w; 46 } 47 dfs(1, 0, 1); 48 for(it = mp.begin(); it != mp.end(); ++it) { 49 int u = (*it).first.first, v = (*it).first.second, w = (*it).second; 50 if(w == 1) Union(0, u, v); 51 if(w <= 2) Union(1, u, v); 52 } 53 for(it = mp.begin(); it != mp.end(); ++it) { 54 int u = (*it).first.first, v = (*it).first.second, w = (*it).second; 55 if(D[u] > D[v]) swap(u, v); 56 if(w == 3) c[Find(0, u)] += r[1][Find(1, v)]; 57 } 58 while(m--) { 59 int a, b, s, t; 60 scanf("%d %d %d %d", &a, &b, &s, &t); 61 if(a > b) swap(a, b); 62 int w = mp[pii(a, b)]; 63 if(w == 3) { 64 c[Find(0, F[Find(1, a)])] -= r[1][Find(1, a)]; 65 c[Find(0, F[Find(1, b)])] -= r[1][Find(1, b)]; 66 Union(1, a, b); 67 mp[pii(a, b)] = 2; 68 c[Find(0, F[Find(1, b)])] += r[1][Find(1, b)]; 69 } 70 if(w == 2) { 71 Union(0, a, b); 72 mp[pii(a, b)] = 1; 73 } 74 int ans1 = 0, ans2 = r[1][Find(1, s)] + c[Find(0, s)]; 75 if(Find(1, s) == Find(1, t) || Find(1, F[Find(0, s)]) == Find(1, t) || Find(0, F[Find(1, t)]) == Find(0, s)) ans1 = 1; 76 if(mp[pii(min(F[Find(0, s)], Find(0, s)), max(F[Find(0, s)], Find(0, s)))] == 3) ans2 += r[1][Find(1, F[Find(0, s)])]; 77 printf("%d %d ", ans1, ans2); 78 } 79 } 80 return 0; 81 }
Problem D. Nothing is Impossible
心灵相通
1 #include <bits/stdc++.h> 2 using namespace std; 3 int a[111], b[111], id[111]; 4 typedef long long LL; 5 6 bool cmp(int i, int j) { 7 return b[i] < b[j]; 8 } 9 10 int main() { 11 int T; 12 scanf("%d", &T); 13 while(T--) { 14 int n, m; 15 scanf("%d %d", &n, &m); 16 for(int i = 1; i <= n; ++i) scanf("%d %d", a + i, b + i), id[i] = i; 17 sort(id + 1, id + 1 + n, cmp); 18 LL t = 1, ans = 0; 19 for(int i = 1; i <= n; ++i) { 20 int x = id[i]; 21 if(t * (b[x] + 1) <= m) t *= (b[x] + 1), ans++; 22 } 23 printf("%lld ", ans); 24 } 25 return 0; 26 }
暴力循环节
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 LL A[11]; 5 6 int L, d[11] = {0, 1, 4, 3, 8, 5, 12, 7, 16, 9, 20}; 7 LL cal(LL x, LL y) { 8 return ((x + y) * (x + y + 1) / 2 + x) % L; 9 } 10 11 int main() { 12 int T; 13 scanf("%d", &T); 14 while(T--) { 15 int Q; 16 scanf("%d", &L); 17 for(int i = 0; i < L; ++i) scanf("%lld", A + i); 18 scanf("%d", &Q); 19 for(int i = 0; i < Q; ++i) { 20 LL x0, y0, x1, y1; 21 scanf("%lld %lld %lld %lld", &x0, &y0, &x1, &y1); 22 LL ans = 0, tmp = 0; 23 24 for(LL j = x0; j < x0 + d[L]; ++j) 25 for(LL k = y0; k < y0 + d[L]; ++k) 26 tmp += A[cal(j, k)]; 27 ans += tmp * ((x1 - x0 + 1) / d[L]) * ((y1 - y0 + 1) / d[L]); 28 29 if(y1 - y0 + 1 > d[L]) { 30 tmp = 0; 31 for(LL j = x0 + (x1 - x0 + 1) / d[L] * d[L]; j <= x1; ++j) 32 for(LL k = y0; k < y0 + d[L]; ++k) 33 tmp += A[cal(j, k)]; 34 ans += tmp * ((y1 - y0 + 1) / d[L]); 35 } 36 37 if(x1 - x0 + 1 > d[L]) { 38 tmp = 0; 39 for(LL k = y0 + (y1 - y0 + 1) / d[L] * d[L]; k <= y1; ++k) 40 for(LL j = x0; j < x0 + d[L]; ++j) 41 tmp += A[cal(j, k)]; 42 ans += tmp * ((x1 - x0 + 1) / d[L]); 43 } 44 45 for(LL j = x0 + (x1 - x0 + 1) / d[L] * d[L]; j <= x1; ++j) 46 for(LL k = y0 + (y1 - y0 + 1) / d[L] * d[L]; k <= y1; ++k) 47 ans += A[cal(j, k)]; 48 printf("%lld ", ans); 49 } 50 } 51 return 0; 52 }
Problem F. Travel Through Time
可持久化平衡树不太会会阿?
依然感觉没那么好做阿大家都是神仙吗?
每个子树里面要维护名次,每次还要把一个系数传递下去T^T
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e6 + 10; 4 typedef long long ll; 5 const ll mod = 1e9 + 7; 6 vector<int> G[maxn]; 7 int B[maxn], deg[maxn]; 8 ll fac[maxn], inv_fac[maxn]; 9 10 vector<int> c[maxn]; 11 int lowbit(int s) { 12 return s & (-s); 13 } 14 void modify(int o, int x, int v) { 15 for (int i = x; i < c[o].size(); i += lowbit(i)) c[o][i] += v; 16 } 17 int query(int o, int x) { 18 int ret = 0; 19 for (int i = x; i > 0; i -= lowbit(i)) ret += c[o][i]; 20 return ret; 21 } 22 23 ll f[maxn]; 24 vector<int> v[maxn]; 25 set<int> s[maxn]; 26 void dfs1(int x, int fa) { 27 f[x] = 1; 28 v[x].clear(), s[x].clear(); 29 for(int i = 0; i < G[x].size(); ++i) { 30 int to = G[x][i]; 31 if(to == fa) continue; 32 dfs1(to, x), f[x] = f[x] * f[to] % mod, v[x].push_back(to), s[x].insert(to); 33 } 34 f[x] = f[x] * fac[v[x].size()] % mod; 35 sort(v[x].begin(), v[x].end()); 36 c[x] = vector<int> (v[x].size() + 1, 0); 37 for(int i = 0; i < v[x].size(); ++i) modify(x, i + 1, 1); 38 } 39 40 ll fp(ll a, ll b) { 41 ll ret = 1ll; 42 while (b) { 43 if (b & 1) ret = ret * a % mod; 44 a = a * a % mod; 45 b >>= 1; 46 } 47 return ret; 48 } 49 ll inv(ll x) { 50 return fp(x, mod - 2); 51 } 52 53 ll ans, p; 54 void dfs2(int x, ll o) { 55 ++p; 56 ll t = 1; 57 for(int i = 0; i < v[x].size(); ++i) t = t * f[v[x][i]] % mod; 58 while(s[x].size()) { 59 int y = lower_bound(v[x].begin(), v[x].end(), B[p]) - v[x].begin(); 60 assert(y <= v[x].size()); 61 ans = (ans + o * t % mod * query(x, y) % mod * fac[s[x].size() - 1]) % mod; 62 if(!p) return; 63 if(p && s[x].find(B[p]) == s[x].end()) {p = 0; return;} 64 else { 65 modify(x, y + 1, -1); 66 s[x].erase(B[p]); 67 t = t * inv(f[B[p]]) % mod; 68 dfs2(B[p], o * fac[s[x].size()] % mod * t % mod); 69 } 70 } 71 } 72 73 int main() { 74 fac[0] = 1; 75 for(int i = 1; i < maxn; ++i) fac[i] = fac[i - 1] * i % mod; 76 inv_fac[0] = inv_fac[1] = 1; 77 for(int i = 2; i < maxn; ++i) inv_fac[i] = (mod - mod / i) * inv_fac[mod % i] % mod; 78 for(int i = 3; i < maxn; ++i) inv_fac[i] = inv_fac[i] * inv_fac[i - 1] % mod; 79 int T; 80 scanf("%d", &T); 81 while(T--) { 82 int n; 83 scanf("%d", &n); 84 for(int i = 1; i <= n; ++i) scanf("%d", B + i), deg[i] = 0, G[i].clear(); 85 B[n + 1] = 0; 86 for(int i = 1; i < n; ++i) { 87 int u, v; 88 scanf("%d %d", &u, &v); 89 G[u].push_back(v); 90 G[v].push_back(u); 91 deg[u]++, deg[v]++; 92 } 93 ans = 0; 94 ll tmp = 1; 95 for(int i = 1; i <= n; ++i) tmp = tmp * fac[deg[i] - 1] % mod; 96 for(int i = 1; i < B[1]; ++i) 97 ans = (ans + tmp * inv_fac[deg[i] - 1] % mod * fac[deg[i]]) % mod; 98 dfs1(B[1], 0); 99 p = 1, dfs2(B[1], 1); 100 printf("%lld ", ans); 101 } 102 return 0; 103 }
Problem H. Eat Cards, Have Fun
啥玩意儿阿?
Problem I. Delightful Formulas
咋回事阿?
谈学姐写的啥玩意儿?
1 #include<bits/stdc++.h> 2 using namespace std; 3 long long a[20][20],b[20][20],c[10],d[10][5],e[10]; 4 char ch; 5 long long n,i,j,k,s,t,T,x,y,f,tot=0,q,ans; 6 int main() 7 { 8 scanf("%d",&T); 9 getchar(); 10 while (T--) 11 { 12 for (i=1;i<=16;i++) 13 { 14 j=0; 15 ch=getchar(); 16 while (j<16) 17 { 18 if ((ch>='0'&&ch<='9')||(ch>='A'&&ch<='F')) 19 { 20 21 j++; 22 if (ch>='1'&&ch<='9') a[i][j]=ch-48; else a[i][j]=ch-'A'+10; 23 if (ch=='0') a[i][j]=16; 24 } 25 ch=getchar(); 26 } 27 28 } 29 for (q=1;q<=16;q+=4) 30 { 31 memset(c,0,sizeof c); 32 while (c[0]==0) 33 { 34 for (i=1;i<=16;i++) 35 for (j=1;j<=16;j++) 36 b[i][j]=a[i][j]; 37 for (i=1;i<=4;i++) 38 { 39 for (j=1;j<=c[i];j++) 40 { 41 x=q;y=(i-1)*4+1; 42 t=b[x][y]; 43 b[x][y]=b[x+3][y]; 44 b[x+3][y]=b[x+3][y+3]; 45 b[x+3][y+3]=b[x][y+3]; 46 b[x][y+3]=t; 47 t=b[x+1][y]; 48 b[x+1][y]=b[x+3][y+1]; 49 b[x+3][y+1]=b[x+2][y+3]; 50 b[x+2][y+3]=b[x][y+2]; 51 b[x][y+2]=t; 52 t=b[x][y+1]; 53 b[x][y+1]=b[x+2][y]; 54 b[x+2][y]=b[x+3][y+2]; 55 b[x+3][y+2]=b[x+1][y+3]; 56 b[x+1][y+3]=t; 57 t=b[x+1][y+1]; 58 b[x+1][y+1]=b[x+2][y+1]; 59 b[x+2][y+1]=b[x+2][y+2]; 60 b[x+2][y+2]=b[x+1][y+2]; 61 b[x+1][y+2]=t; 62 } 63 } 64 f=0; 65 for (i=q;i<=q+3;i++) 66 { 67 s=0;t=1; 68 for (j=1;j<=16;j++) 69 { 70 s+=b[i][j]; 71 t*=b[i][j]; 72 if (t>20922789888000) break; 73 } 74 if (s!=136||t!=20922789888000) 75 { 76 f=1; 77 break; 78 } 79 } 80 if (f==0) 81 { 82 t=(q-1)/4+1; 83 d[t][1]=c[1];d[t][2]=c[2];d[t][3]=c[3];d[t][4]=c[4]; 84 break; 85 } 86 k=4; 87 while (c[k]==3) 88 { 89 c[k]=0; 90 k--; 91 } 92 c[k]++; 93 } 94 t=(q-1)/4+1; 95 } 96 ans=10000; 97 memset(e,0,sizeof e); 98 while (e[0]==0) 99 { 100 for (i=1;i<=16;i++) 101 for (j=1;j<=16;j++) 102 b[i][j]=a[i][j]; 103 for (q=1;q<=4;q++) 104 { 105 for (i=1;i<=4;i++) 106 { 107 c[i]=(d[q][i]+2*e[q])%4; 108 } 109 for (i=1;i<=4;i++) 110 { 111 for (j=1;j<=c[i];j++) 112 { 113 x=(q-1)*4+1;y=(i-1)*4+1; 114 t=b[x][y]; 115 b[x][y]=b[x+3][y]; 116 b[x+3][y]=b[x+3][y+3]; 117 b[x+3][y+3]=b[x][y+3]; 118 b[x][y+3]=t; 119 t=b[x+1][y]; 120 b[x+1][y]=b[x+3][y+1]; 121 b[x+3][y+1]=b[x+2][y+3]; 122 b[x+2][y+3]=b[x][y+2]; 123 b[x][y+2]=t; 124 t=b[x][y+1]; 125 b[x][y+1]=b[x+2][y]; 126 b[x+2][y]=b[x+3][y+2]; 127 b[x+3][y+2]=b[x+1][y+3]; 128 b[x+1][y+3]=t; 129 t=b[x+1][y+1]; 130 b[x+1][y+1]=b[x+2][y+1]; 131 b[x+2][y+1]=b[x+2][y+2]; 132 b[x+2][y+2]=b[x+1][y+2]; 133 b[x+1][y+2]=t; 134 } 135 } 136 } 137 f=0; 138 for (i=1;i<=16;i++) 139 { 140 s=0;t=1; 141 for (j=1;j<=16;j++) 142 { 143 s+=b[j][i]; 144 t*=b[j][i]; 145 if (t>20922789888000) break; 146 } 147 if (s!=136||t!=20922789888000) 148 { 149 f=1; 150 break; 151 } 152 } 153 if (f==0) 154 { 155 s=0; 156 for (q=1;q<=4;q++) 157 { 158 for (i=1;i<=4;i++) 159 { 160 s+=(d[q][i]+2*e[q])%4; 161 } 162 } 163 if (s<ans) ans=s; 164 } 165 k=4; 166 while (e[k]==1) 167 { 168 e[k]=0; 169 k--; 170 } 171 e[k]++; 172 } 173 printf("%lld ",ans); 174 } 175 }
Problem K. Expression in Memories
随便判判
1 #include <bits/stdc++.h> 2 using namespace std; 3 char s[555]; 4 5 bool d(char c) { 6 return c >= '0' && c <= '9'; 7 } 8 9 int main() { 10 int T; 11 scanf("%d", &T); 12 while(T--) { 13 scanf("%s", s + 1); 14 int l = strlen(s + 1), ok = 1; 15 for(int i = 1; i <= l; ++i) { 16 if(s[i] == '?') s[i] = '1'; 17 if(s[i] == '0' && i < l) { 18 if(i > 1 && d(s[i - 1])) continue; 19 if(d(s[i + 1])) ok = 0; 20 if(s[i + 1] == '?') s[i + 1] = '+'; 21 } 22 if(s[i] == '+' || s[i] == '*') { 23 if(i == 1) ok = 0; 24 else if(i == l) ok = 0; 25 else if(s[i + 1] == '+' || s[i + 1] == '*') ok = 0; 26 else if(s[i + 1] == '?') s[i + 1] = '1'; 27 } 28 } 29 if(!ok) puts("IMPOSSIBLE"); 30 else puts(s + 1); 31 } 32 return 0; 33 }
Problem L. Graph Theory Homework
签到题
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 10; 4 int w[maxn]; 5 6 int main() { 7 int T; 8 scanf("%d", &T); 9 while(T--) { 10 int n; 11 scanf("%d", &n); 12 for(int i = 1; i <= n; ++i) scanf("%d", w + i); 13 printf("%d ", (int) sqrt(abs(w[1] - w[n]))); 14 } 15 return 0; 16 }