2013_CSUST_3_23校内训练赛第一场【old】【hdu 3496、2191、4508、4506、2181 POJ 3264 3210 3094】
来源:互联网 发布:优化企业内部控制制度 编辑:程序博客网 时间:2024/06/11 20:17
训练赛(Older)#001
题解(F):
1不知道 二维多重背包。。。
2多重背包模板题
3完全背包模板题
4线段树求区间最值 模板题
5幂取模乱搞
6DFS
7水题
8水题
ID Origin Title
B
悼念512汶川大地震遇难同胞——珍惜现在,感恩生活
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8868 Accepted Submission(s): 3719
为了挽救灾区同胞的生命,心系灾区同胞的你准备自己采购一些粮食支援灾区,现在假设你一共有资金n元,而市场有m种大米,每种大米都是袋装产品,其价格不等,并且只能整袋购买。
请问:你用有限的资金最多能采购多少公斤粮食呢?
后记:
人生是一个充满了变数的生命过程,天灾、人祸、病痛是我们生命历程中不可预知的威胁。
月有阴晴圆缺,人有旦夕祸福,未来对于我们而言是一个未知数。那么,我们要做的就应该是珍惜现在,感恩生活——
感谢父母,他们给予我们生命,抚养我们成人;
感谢老师,他们授给我们知识,教我们做人
感谢朋友,他们让我们感受到世界的温暖;
感谢对手,他们令我们不断进取、努力。
同样,我们也要感谢痛苦与艰辛带给我们的财富~
18 22 100 44 100 2
400
思路:多重背包模板题
转换为01背包思想
procedure MultiplePack(cost,weight,amount)
if cost*amount>=V
CompletePack(cost,weight)
return
integer k=1
while k<num
ZeroOnePack(k*cost,k*weight)
amount=amount-k
k=k*2
ZeroOnePack(amount*cost,amount*weight)
#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespace std;const int maxn = 110;const int Maxn = 20*100+10;int dp[maxn];int n,m;int N;int v[Maxn],w[Maxn];struct Node{int v,w,c;}t[maxn];int main(){int a,b,e;int T;int n,m;scanf("%d",&T);while(T--){int N = 0;memset(dp,0,sizeof(dp));scanf("%d%d", &n, &m);for(int i = 0; i < m; i++){scanf("%d%d%d", &a, &b,&e);t[i].v=a;t[i].w=b;t[i].c=e;N+=e;}int k = 0;int s= 0;for(int i = 0; i < m; i++){ k = 1;while(k<20 && t[i].c >= k){v[s] = t[i].v*k;w[s++] = t[i].w*k;t[i].c -= k;k = k*2;} v[s] = t[i].v*t[i].c; w[s++] = t[i].w*t[i].c;}for(int i = 0; i < s; i++){for(int j = n; j >= v[i]; j--)dp[j] = max(dp[j], dp[j-v[i]]+w[i]);}printf("%d\n", dp[n]);}return 0;}
C
湫湫系列故事——减肥记I
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 922 Accepted Submission(s): 454
但是对于女生来说,卡路里(热量)是天敌啊!
资深美女湫湫深谙“胖来如山倒,胖去如抽丝”的道理,所以她希望你能帮忙制定一个食谱,能使她吃得开心的同时,不会制造太多的天敌。
当然,为了方便你制作食谱,湫湫给了你每日食物清单,上面描述了当天她想吃的每种食物能带给她的幸福程度,以及会增加的卡路里量。
每组数据以一个整数n开始,表示每天的食物清单有n种食物。
接下来n行,每行两个整数a和b,其中a表示这种食物可以带给湫湫的幸福值(数值越大,越幸福),b表示湫湫吃这种食物会吸收的卡路里量。
最后是一个整数m,表示湫湫一天吸收的卡路里不能超过m。
[Technical Specification]
1. 1 <= n <= 100
2. 0 <= a,b <= 100000
3. 1 <= m <= 100000
33 37 79 91051 15 310 36 87 56
1020
思路:完全背包模板题
procedure CompletePack(cost,weight)
for v=cost..V
f[v]=max{f[v],f[v-c[i]]+w[i]}
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int maxn = 100000+10;int dp[maxn];int w[110],v[110];int n,m;int main(){while(scanf("%d", &n) != EOF){memset(dp,0,sizeof(dp));//int a,b;for(int i = 0; i < n; i++){scanf("%d%d", &w[i], &v[i]);}scanf("%d", &m);for(int i = 0; i < n; i++){for(int j = v[i]; j <=m; j++)dp[j] = max(dp[j], dp[j-v[i]]+w[i]);}printf("%d\n", dp[m]);}return 0;}
D
Description
For the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things simple, he will take a contiguous range of cows from the milking lineup to play the game. However, for all the cows to have fun they should not differ too much in height.
Farmer John has made a list of Q (1 ≤ Q ≤ 200,000) potential groups of cows and their heights (1 ≤ height ≤ 1,000,000). For each group, he wants your help to determine the difference in height between the shortest and the tallest cow in the group.
Input
Lines 2..N+1: Line i+1 contains a single integer that is the height of cow i
Lines N+2..N+Q+1: Two integers A and B (1 ≤ A ≤ B ≤ N), representing the range of cows from A to B inclusive.
Output
Sample Input
6 31734251 54 62 2
Sample Output
630
Source
思路:区间最值问题。
详细分析见:POJ 3264 区间最值模板题
/**Accepted*8404 KB*3579 ms*G++*1022 B2013-03-23 21:57:28*O(n*logn) *第一次写RMQ套用lrj的模板,效率较低,模板较坑 Orz */#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;const int maxn = 50000+10;int d_max[maxn][20];int d_min[maxn][20];int A[maxn];int n,q;void RMQ_init(){for(int i = 1; i <= n; i++) d_max[i][0] = d_min[i][0] = A[i];for(int j = 1; j <= log((double)(n+1))/log(2.0); j++)for(int i = 1; i+(1<<j)-1 <= n; i++){d_min[i][j] = min(d_min[i][j-1], d_min[i + (1<<(j-1))][j-1]);d_max[i][j] = max(d_max[i][j-1], d_max[i + (1<<(j-1))][j-1]);}}int RMQ_Max(int L, int R){int k = (int)(log((double)(R-L+1)) / log(2.0));return max(d_max[L][k], d_max[R-(1 << k)+1][k]);}int RMQ_Min(int L, int R){int k = (int)(log((double)(R-L+1)) / log(2.0));return min(d_min[L][k], d_min[R-(1 << k)+1][k]);}int main(){while(scanf("%d%d", &n, &q) != EOF){for(int i = 1; i <= n; i++)scanf("%d", &A[i]);RMQ_init();int a,b;for(int i = 1; i <= q; i++){scanf("%d%d", &a, &b);printf("%d\n",RMQ_Max(a,b) - RMQ_Min(a,b));}}return 0;}
E
小明系列故事——师兄帮帮忙
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2043 Accepted Submission(s): 476
所以,他现在私下求你帮忙解决这道题目,题目是这样的:
给你n个数字,分别是a1,a2,a3,a4,a5……an,这些数字每过一个单位时间就会改变,假设上一个单位时间的数字为a1’,a2’,a3’……an’,那么这个单位时间的数字a[i] = a[i - 1]’ * K(i == 1的时候a[1] = a[n]’ * K),其中K为给定的系数。
现在的问题就是求第t单位时间的时候这n个数字变成了什么了?由于数字可能会很大,所以只要你输出数字对10^9 + 7取余以后的结果。
每组数据有两行,第一行包含输入三个整数n, t, k,其中n代表数字个数,t代表第t个单位时间,k代表系数;第二行输入n个数字ai,代表每个数字开始的时候是多少。
[Technical Specification]
T <= 100
1 <= n <= 10 ^ 4
0 <= t <= 10 ^ 9 其中 t = 0 表示初始状态
1 <= k <= 10 ^ 9
1 <= ai<= 10 ^ 9
23 2 51 2 33 0 51 2 3
50 75 251 2 3
思路:幂取模问题。
先将数组元素乘以 k^t %mod ,然后再对应于数组元素个数 n 确定其周期性,根据 t%n 顺时针旋转来确定首位置。
(PS:测试时注意首位置不要比 n 大)。
注意:整数的溢出(int *int 可能会超int)
循环输出时,首位置的确定,最好用下面那组数据测试一下,否则WA到正无穷啊
#include<cstdio>const int maxn = 10000+10;const int mod = 1000000000+7;int a[maxn];int n,t,k;int mul(int m,int n)//m^n{int b = 1;while(n>0){if(n&1) b = ((long long)b*m)%mod;n = n >>1;m = ((long long)m*m)%mod;}return (int)b;}int main(){int T;scanf("%d", &T);while(T--){scanf("%d%d%d", &n, &t, &k);for(int i = 1; i <= n; i++)scanf("%d",&a[i]); int temp = mul(k,t);for(int i = 1; i <= n; i++){a[i] = ((long long)a[i]*temp)%mod;a[i] = (int)a[i];}t%=n; int x =(n-t+1) ;if(x>n) x%=n;//printf("%d\n",x); for(int i = x; i <= n; i++) { if(i == x) printf("%d",a[i]); else printf(" %d",a[i]); }for(int i=1; i < x; i++)printf(" %d",a[i]);printf("\n");//printf("\n");//}return 0;}/*64 1 1 1 2 3 44 2 11 2 3 44 3 11 2 3 44 4 11 2 3 44 5 11 2 3 44 6 11 2 3 4*/
F
哈密顿绕行世界问题
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 612 Accepted Submission(s): 369
2 5 201 3 122 4 103 5 81 4 65 7 196 8 174 7 98 10 163 9 1110 12 152 11 1312 14 2013 15 1811 14 169 15 177 16 1814 17 196 18 201 13 1950
1: 5 1 2 3 4 8 7 17 18 14 15 16 9 10 11 12 13 20 19 6 52: 5 1 2 3 4 8 9 10 11 12 13 20 19 18 14 15 16 17 7 6 53: 5 1 2 3 10 9 16 17 18 14 15 11 12 13 20 19 6 7 8 4 54: 5 1 2 3 10 11 12 13 20 19 6 7 17 18 14 15 16 9 8 4 55: 5 1 2 12 11 10 3 4 8 9 16 15 14 13 20 19 18 17 7 6 56: 5 1 2 12 11 15 14 13 20 19 18 17 16 9 10 3 4 8 7 6 57: 5 1 2 12 11 15 16 9 10 3 4 8 7 17 18 14 13 20 19 6 58: 5 1 2 12 11 15 16 17 18 14 13 20 19 6 7 8 9 10 3 4 59: 5 1 2 12 13 20 19 6 7 8 9 16 17 18 14 15 11 10 3 4 510: 5 1 2 12 13 20 19 18 14 15 11 10 3 4 8 9 16 17 7 6 511: 5 1 20 13 12 2 3 4 8 7 17 16 9 10 11 15 14 18 19 6 512: 5 1 20 13 12 2 3 10 11 15 14 18 19 6 7 17 16 9 8 4 513: 5 1 20 13 14 15 11 12 2 3 10 9 16 17 18 19 6 7 8 4 514: 5 1 20 13 14 15 16 9 10 11 12 2 3 4 8 7 17 18 19 6 515: 5 1 20 13 14 15 16 17 18 19 6 7 8 9 10 11 12 2 3 4 516: 5 1 20 13 14 18 19 6 7 17 16 15 11 12 2 3 10 9 8 4 517: 5 1 20 19 6 7 8 9 10 11 15 16 17 18 14 13 12 2 3 4 518: 5 1 20 19 6 7 17 18 14 13 12 2 3 10 11 15 16 9 8 4 519: 5 1 20 19 18 14 13 12 2 3 4 8 9 10 11 15 16 17 7 6 520: 5 1 20 19 18 17 16 9 10 11 15 14 13 12 2 3 4 8 7 6 521: 5 4 3 2 1 20 13 12 11 10 9 8 7 17 16 15 14 18 19 6 522: 5 4 3 2 1 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 523: 5 4 3 2 12 11 10 9 8 7 6 19 18 17 16 15 14 13 20 1 524: 5 4 3 2 12 13 14 18 17 16 15 11 10 9 8 7 6 19 20 1 525: 5 4 3 10 9 8 7 6 19 20 13 14 18 17 16 15 11 12 2 1 526: 5 4 3 10 9 8 7 17 16 15 11 12 2 1 20 13 14 18 19 6 527: 5 4 3 10 11 12 2 1 20 13 14 15 16 9 8 7 17 18 19 6 528: 5 4 3 10 11 15 14 13 12 2 1 20 19 18 17 16 9 8 7 6 529: 5 4 3 10 11 15 14 18 17 16 9 8 7 6 19 20 13 12 2 1 530: 5 4 3 10 11 15 16 9 8 7 17 18 14 13 12 2 1 20 19 6 531: 5 4 8 7 6 19 18 17 16 9 10 3 2 12 11 15 14 13 20 1 532: 5 4 8 7 6 19 20 13 12 11 15 14 18 17 16 9 10 3 2 1 533: 5 4 8 7 17 16 9 10 3 2 1 20 13 12 11 15 14 18 19 6 534: 5 4 8 7 17 18 14 13 12 11 15 16 9 10 3 2 1 20 19 6 535: 5 4 8 9 10 3 2 1 20 19 18 14 13 12 11 15 16 17 7 6 536: 5 4 8 9 10 3 2 12 11 15 16 17 7 6 19 18 14 13 20 1 537: 5 4 8 9 16 15 11 10 3 2 12 13 14 18 17 7 6 19 20 1 538: 5 4 8 9 16 15 14 13 12 11 10 3 2 1 20 19 18 17 7 6 539: 5 4 8 9 16 15 14 18 17 7 6 19 20 13 12 11 10 3 2 1 540: 5 4 8 9 16 17 7 6 19 18 14 15 11 10 3 2 12 13 20 1 541: 5 6 7 8 4 3 2 12 13 14 15 11 10 9 16 17 18 19 20 1 542: 5 6 7 8 4 3 10 9 16 17 18 19 20 13 14 15 11 12 2 1 543: 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 544: 5 6 7 8 9 16 17 18 19 20 1 2 12 13 14 15 11 10 3 4 545: 5 6 7 17 16 9 8 4 3 10 11 15 14 18 19 20 13 12 2 1 546: 5 6 7 17 16 15 11 10 9 8 4 3 2 12 13 14 18 19 20 1 547: 5 6 7 17 16 15 11 12 13 14 18 19 20 1 2 3 10 9 8 4 548: 5 6 7 17 16 15 14 18 19 20 13 12 11 10 9 8 4 3 2 1 549: 5 6 7 17 18 19 20 1 2 3 10 11 12 13 14 15 16 9 8 4 550: 5 6 7 17 18 19 20 13 14 15 16 9 8 4 3 10 11 12 2 1 551: 5 6 19 18 14 13 20 1 2 12 11 15 16 17 7 8 9 10 3 4 552: 5 6 19 18 14 15 11 10 9 16 17 7 8 4 3 2 12 13 20 1 553: 5 6 19 18 14 15 11 12 13 20 1 2 3 10 9 16 17 7 8 4 554: 5 6 19 18 14 15 16 17 7 8 9 10 11 12 13 20 1 2 3 4 555: 5 6 19 18 17 7 8 4 3 2 12 11 10 9 16 15 14 13 20 1 556: 5 6 19 18 17 7 8 9 16 15 14 13 20 1 2 12 11 10 3 4 557: 5 6 19 20 1 2 3 10 9 16 15 11 12 13 14 18 17 7 8 4 558: 5 6 19 20 1 2 12 13 14 18 17 7 8 9 16 15 11 10 3 4 559: 5 6 19 20 13 12 11 10 9 16 15 14 18 17 7 8 4 3 2 1 560: 5 6 19 20 13 14 18 17 7 8 4 3 10 9 16 15 11 12 2 1 5
思路:简单DFS应用,记录路径。注意格式和输出顺序要先给点排序,还有就是执行dfs的条件要注意下,我标记了的。
/**F*Accepted*204 KB*0 ms*G++*867 B*2013-03-26 */ #include<cstdio>#include<cstring>#include<algorithm>using namespace std;int path[22];int point[21][3];bool vis[21];int m;int Case;void dfs(int a, int n){vis[a] = true;path[n] = a;if(n == 21 && path[n] == m) //回到起点 {printf("%d: ",++Case);for(int i = 1; i <= 21; i++) printf(" %d", path[i]);printf("\n");return;}else if(n >= 21) return;for(int i = 0; i < 3; i++){int x = point[a][i];if((x != m && !vis[x]) || (x == m && n == 20)) //如果没有走过,或者下一个点回到起点 { //注意:前一个条件如果没有写 x != m 则会影响后面的结果 也就是 m 会在路径中重复出现 dfs(x, n+1);vis[x] = false;} } }int main(){for(int i = 1; i <= 20; i++){scanf("%d%d%d", &point[i][0], &point[i][1], &point[i][2]);sort(point[i], point[i]+3);} while(scanf("%d", &m) != EOF){Case = 0;if(m == 0) break;memset(vis, false, sizeof(vis));dfs(m, 1);}return 0;}
G
Description
Snoopy has three coins. One day he tossed them on a table then and tried to flip some of them so that they had either all heads or all tails facing up. After several attempts, he found that regardless of the initial configuration of the coins, he could always achieve the goal by doing exactly two flippings, under the condition that only one coin could be flipped each time and a coin could be flipped more than once. He also noticed that he could never succeed with less than two flippings.
Snoopy then wondered, if he had n coins, was there a minimum number x such that he could do exactly x flippings to satisfy his requirements?
Input
The input contains multiple test cases. Each test case consists of a single positive integer n (n < 10,000) on a separate line. A zero indicates the end of input and should not be processed.
Output
For each test case output a single line containing your answer without leading or trailing spaces. If the answer does not exist, output “No Solution!
”
Sample Input
230
Sample Output
No Solution!2
Source
比赛时实在没看懂是什么意思,现在想起,就算当时看懂了也应该不会想到这儿吧。。。下面copy个牛人的分析。
分析来自:点击打开链接
题意:Snoopy想问下,若有n枚硬币,这n枚硬币的初始状态是任意的,则至少需要翻转几次,才能保证对于任何一种初始状态而 言,都能变成n枚硬币全为正或全为反。
思路:若n为偶数:
源代码:(这题考的是题意和推理,不是代码)
/**Accepted*132 KB*0 ms*C++*176 B*/#include<cstdio>int main(){int n;while(scanf("%d", &n) != EOF){if(n == 0) break;if(n%2 == 0) printf("No Solution!\n");else printf("%d\n", n-1);}return 0;}
H
Description
A checksum is an algorithm that scans a packet of data and returns a single number. The idea is that if the packet is changed, the checksum will also change, so checksums are often used for detecting transmission errors, validating document contents, and in many other situations where it is necessary to detect undesirable changes in data.
For this problem, you will implement a checksum algorithm called Quicksum. A Quicksum packet allows only uppercase letters and spaces. It always begins and ends with an uppercase letter. Otherwise, spaces and letters can occur in any combination, including consecutive spaces.
A Quicksum is the sum of the products of each character's position in the packet times the character's value. A space has a value of zero, while letters have a value equal to their position in the alphabet. So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets "ACM
" and "MID CENTRAL
":
ACM: 1*1 + 2*3 + 3*13 = 46MID CENTRAL: 1*13 + 2*9 + 3*4 + 4*0 + 5*3 + 6*5 + 7*14 + 8*20 + 9*18 + 10*1 + 11*12 = 650
Input
The input consists of one or more packets followed by a line containing only # that signals the end of the input. Each packet is on a line by itself, does not begin or end with a space, and contains from 1 to 255 characters.
Output
For each packet, output its Quicksum on a separate line in the output.
Sample Input
ACMMID CENTRALREGIONAL PROGRAMMING CONTESTACNA C MABCBBC#
Sample Output
46650469049751415
Source
思路:字符串简单处理,直接看代码即可,注意空格的处理就好了。
#include<cstdio>#include<cstring>char s[300];int main(){char c;int ans = 0;;while((c=getchar()) != '#'){ans = 0;int k = 0;memset(s,-1,sizeof(s));if(c != '\n'){if(c != ' ') s[k++] = c -'A'+1;else s[k++] = 0;}while((c=getchar()) != '\n'){if(c != ' ') s[k++] = c -'A'+1;else s[k++] = 0;}for(int i = 0; i < k; i++){//printf("%d ",s[k])ans += s[i]*(i+1);}printf("%d\n", ans);ans = 0;k = 0;memset(s,-1,sizeof(s));}return 0;}
- 2013_CSUST_3_23校内训练赛第一场【old】【hdu 3496、2191、4508、4506、2181 POJ 3264 3210 3094】
- ACM校内赛------预赛热身赛第一场
- hdu 4602 partition 2013多校联合训练第一场
- 第一场个人训练赛
- 训练赛第一场总结
- 2013年CSUST新生训练赛第一场【未完待续】
- 第一场训练赛UVALive 6907
- SWPU暑假第一场训练赛题解
- 2016多校联合训练赛 第一场1004 GCD hdu 5726
- 第一场个人训练赛——A-ASCII码排序(HDU 2000)
- 第一场个人训练赛——B-计算两点间的距离(HDU 2001)
- 第一场个人训练赛——C-计算球体积(HDU 2002)
- 第一场个人训练赛——D-求绝对值(HDU 2003)
- 第一场个人训练赛——E-成绩转换(HDU 2004)
- 第一场个人训练赛——F-第几天?(HDU 2005)
- hdu 4607 park visit 2013多校联合训练第一场
- 2013 - ECJTU 暑期12级训练赛第一场-Problem-A
- 2013 - ECJTU 暑期12级训练赛第一场-problem-B
- Oracle数据库之学前总结
- hdu 4512 吉哥系列故事——完美队形I(最长公共上升序列)
- MyEclipse内存不足配置
- 在jquery中使用$("#form").submit() 重写提交表单时不起作用
- HDU 2073 无限的路
- 2013_CSUST_3_23校内训练赛第一场【old】【hdu 3496、2191、4508、4506、2181 POJ 3264 3210 3094】
- vs2010与opencv2.2
- 蓝桥杯练习一
- get & post区别
- 国际化之struts2实现研究
- 最近自学的感受
- CVT 网易
- 乔姆斯基文法分类【0型1型2型3型文法】
- VC6.0 乱码问题解决办法