本来打算去上课的,但给我一觉睡过去了 。。。。然后就有了这篇题解。。。
250pts
Problem Statement |
|||||||||||||
Fox Ciel thinks that the number 41312432 is interesting. This is because of the following property: There is exactly 1 digit between the two 1s, there are exactly 2 digits between the two 2s, and so on. Formally, Ciel thinks that a number X is interesting if the following property is satisfied: For each D between 0 and 9, inclusive, X either does not contain the digit D at all, or it contains exactly two digits D, and there are precisely D other digits between them. You are given a string x that contains the digits of a positive integer. Return "Interesting" if that integer is interesting, otherwise return "Not interesting". |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | x will correspond to an integer between 1 and 1,000,000,000, inclusive. | ||||||||||||
- | x will not start with a '0'. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
|||||||||||||
4) | |||||||||||||
|
|||||||||||||
5) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
int cnt[12]; int pos[12][5]; string InterestingNumber::isInteresting(string x) { fill(cnt,cnt+12,0); memset(pos,0,sizeof(pos)); int n=x.size(); for(int i=0;i<n;i++) { cnt[x[i]-'0']++; pos[x[i]-'0'][cnt[x[i]-'0']]=i; if(cnt[x[i]-'0']>2) return "Not interesting"; } for(int i=0;i<=9;i++) { if(!cnt[i]) continue; if(pos[i][2]-pos[i][1]-1==i) continue; return "Not interesting"; } return "Interesting"; }
Problem Statement |
|||||||||||||
For any non-empty sequence of positive integers s1, s2, ..., sK their least common multiple is the smallest positive integer that is divisible by each of the given numbers. We will use "lcm" to denote the least common multiple. For example, lcm(3) = 3, lcm(4,6) = 12, and lcm(2,5,7) = 70. You are given a vector <int> S and an int x. Find out whether we can select some elements from S in such a way that their least common multiple will be precisely x. Formally, we are looking for some s1, s2, ..., sK, K >= 1, such that each si belongs to S, and x=lcm(s1, s2, ..., sK). Return "Possible" if such elements of S exist, and "Impossible" if they don't. |
|||||||||||||
Definition |
|||||||||||||
|
|||||||||||||
Limits |
|||||||||||||
|
|||||||||||||
Constraints |
|||||||||||||
- | S will contain between 1 and 50 elements, inclusive. | ||||||||||||
- | Each element in S will be between 1 and 1,000,000,000, inclusive. | ||||||||||||
- | Elements in S will be distinct. | ||||||||||||
- | x will be between 2 and 1,000,000,000, inclusive. | ||||||||||||
Examples |
|||||||||||||
0) | |||||||||||||
|
|||||||||||||
1) | |||||||||||||
|
|||||||||||||
2) | |||||||||||||
|
|||||||||||||
3) | |||||||||||||
|
|||||||||||||
4) | |||||||||||||
|
|||||||||||||
5) | |||||||||||||
|
|||||||||||||
6) | |||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved
int gcd(int a,int b) { return b?gcd(b,a%b):a; } int lcm(int a,int b) { return b/gcd(a,b)*a; } string LCMSetEasy::include(vector <int> S,int x) { vector<int> vk; for(int i=0,n=S.size();i<n;i++) { if(x%S[i]==0) { vk.push_back(S[i]); } } int lc=1; for(int i=0,n=vk.size();i<n;i++) { lc=lcm(lc,vk[i]); } if(lc==x) return "Possible"; else return "Impossible"; }
1000pts:鉴于TC的机器很快,所以直接枚举所有的可能(100w而已。。。
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
int G[10][10]; int getone(int x) { int t=0; while(x) { t++; x&=(x-1); } return t; } int ElephantDrinkingEasy::maxElephants(vector <string> mp) { int n=mp.size(),m=4*n; int ans=0; for(int k=0;k<(1<<m);k++) { int tt=getone(k); bool ok=true; if(k<ans) continue; memset(G,0,sizeof(G)); ///down for(int i=0;i<n;i++) { if(!(k&(1<<i))) continue; bool water=false; for(int j=0;j<n;j++) { if(G[j][i]) {ok=false; break; } G[j][i]=1; if(mp[j][i]=='Y') {water=true; break;} } if(water==false) ok=false; if(ok==false) break; } if(!ok) continue; ///up for(int i=0;i<n;i++) { if(!(k&(1<<(i+n)))) continue; bool water=false; for(int j=n-1;j>=0;j--) { if(G[j][i]) {ok=false;break;} G[j][i]=1; if(mp[j][i]=='Y') {water=true; break;} } if(water==false) ok=false; if(ok==false) break; } if(!ok) continue; ///left for(int i=0;i<n;i++) { if(!(k&(1<<(i+2*n)))) continue; bool water=false; for(int j=0;j<n;j++) { if(G[i][j]) {ok=false;break;} G[i][j]=1; if(mp[i][j]=='Y') {water=true; break;} } if(water==false) ok=false; if(ok==false) break; } if(!ok) continue; ///right for(int i=0;i<n;i++) { if(!(k&(1<<(i+3*n)))) continue; bool water=false; for(int j=n-1;j>=0;j--) { if(G[i][j]) {ok=false;break;} G[i][j]=1; if(mp[i][j]=='Y') {water=true; break;} } if(water==false) ok=false; if(ok==false) break; } if(!ok) continue; ans=max(ans,tt); } return ans; }