10.2训练赛
http://vjudge.net/vjudge/contest/view.action?cid=57492#overview
f:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 6 const int maxn = 13; 7 8 int a[maxn]; 9 int main() { 10 int t; 11 scanf("%d",&t); 12 while(t--) { 13 int n; 14 scanf("%d",&n); 15 for(int i = 1; i <= n; i++) { 16 scanf("%d",&a[i]); 17 } 18 bool flag = false; 19 if(a[2] % a[1] == 0) { 20 int xx = a[2] / a[1]; 21 bool ok = true; 22 for(int i = 3; i <= n; i++) { 23 if(a[i] % a[i - 1] != 0 || a[i] / a[i - 1] != xx) { 24 ok = false; 25 break; 26 } 27 } 28 if(ok) flag = true; 29 } 30 if(flag) { 31 printf("%d\n", a[n] * a[2] / a[1]); 32 continue; 33 } 34 int ans = 0; 35 for(int d1 = - 100; d1 <= 100; d1++) { 36 for(int d2 = - 100; d2 <= 100; d2++) { 37 bool ok = true; 38 for(int i = 3; i <= n; i++) { 39 if(a[i] != d1 * a[i - 1] + d2 * a[i - 2]) { 40 ok = false; 41 break; 42 } 43 } 44 if(ok) { 45 flag = true; 46 ans = d1 * a[n] + d2 * a[n - 1]; 47 break; 48 } 49 } 50 if(flag) break; 51 } 52 if(flag) { 53 printf("%d\n", ans); 54 continue; 55 } 56 for(int d1 = -100; d1 <= 100; d1 ++) { 57 for(int d2 = -100; d2 <= 100; d2++) { 58 for(int d3 = -100; d3 <= 100; d3++) { 59 bool ok = true; 60 for(int i = 4; i <= n; i++) { 61 if(a[i] != d1 * a[i - 1] + d2 * a[i - 2] + d3 * a[i - 3]) { 62 ok = false; 63 break; 64 } 65 } 66 if(ok) { 67 flag = true; 68 ans = d1 * a[n] + d2 * a[n - 1] + d3 * a[n - 2]; 69 break; 70 } 71 } 72 if(flag) break; 73 } 74 if(flag) break; 75 } 76 printf("%d\n", ans); 77 } 78 return 0; 79 }
a:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 15; 8 const int maxm = 35; 9 10 vector<int> v[maxn]; 11 int nu[maxm]; 12 int val[maxn]; 13 14 int main() { 15 int t; 16 int n, m; 17 int k, num; 18 scanf("%d",&t); 19 while(t--) { 20 scanf("%d %d",&n, &m); 21 for(int i = 1; i <= n; i++) { 22 v[i].clear(); 23 scanf("%d",&k); 24 while(k--) { 25 scanf("%d",&num); 26 v[i].push_back(num); 27 } 28 scanf("%d", &val[i]); 29 } 30 memset(nu, 0, sizeof(nu)); 31 for(int i = 1; i <= m; i++) { 32 scanf("%d",& nu[i]); 33 } 34 int ans = 0; 35 for(int i = 1; i <= n; i++) { 36 int xx = 105; 37 for(int j = 0; j < v[i].size(); j++) { 38 xx = min(xx, nu[v[i][j]]); 39 } 40 ans += xx * val[i]; 41 } 42 printf("%d\n",ans); 43 } 44 return 0; 45 }
e:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 7 int eps(double x) { 8 if(fabs(x) < 1e-6) return 0; 9 if(x < 0) return -1; 10 return 1; 11 } 12 13 double zhuan(double xx) { 14 xx *= 1000; 15 int a = (int) (xx + 0.00001); 16 int b = a / 10; 17 if(a % 10 >= 5) b++; 18 double c = (double) b / 100; 19 return c; 20 } 21 22 int main() { 23 int t; 24 double a, b, c; 25 scanf("%d", &t); 26 while(t--) { 27 scanf("%lf %lf %lf", &a, &b, &c); 28 bool flag = false; int ans = 0; 29 a /= 100; 30 for(int i = 1; i <= 1200; i++) { 31 double xx = b * a; 32 xx = zhuan(xx); 33 b += xx; 34 b -= c; 35 if(eps(b) != 1) { 36 flag = true; 37 ans = i; 38 break; 39 } 40 } 41 if(flag) { 42 printf("%d\n", ans); 43 } else puts("impossible"); 44 } 45 return 0; 46 }
g:
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector> 5 using namespace std; 6 7 const int maxn = 25; 8 int a[maxn]; 9 int dp[1 << 21]; 10 11 int main() { 12 int t; 13 scanf("%d",&t); 14 while(t--) { 15 int n;int num;int d; 16 scanf("%d",&n); 17 for(int i = 0; i < (1 << n); i++) { 18 dp[i] = 100; 19 } 20 for(int i = 1; i <= n; i++) { 21 a[i] = 1 << ( i - 1 ); 22 scanf("%d",&num); 23 while(num--) { 24 scanf("%d",&d); 25 a[i] += (1 << (d - 1)); 26 } 27 dp[a[i]] = 1; 28 } 29 for(int i = 1; i <= n; i++) { 30 for(int j = 0; j < (1 << n); j++) { 31 if(dp[j] <= 20) { 32 dp[j | a[i]] = min(dp[j|a[i]], dp[j] + 1); 33 } 34 } 35 } 36 printf("%d\n",dp[(1 << n) - 1]); 37 } 38 return 0; 39 }