HDU - 5190 - Go to movies && 5191 - Building Blocks (BC#34 A,B)
来源:互联网 发布:日本杂志模特知乎 编辑:程序博客网 时间:2024/03/29 06:37
Go to movies
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 99 Accepted Submission(s): 67
Problem Description
Winter holiday is coming!As the monitor, LeLe plans to go to the movies.
Because the winter holiday tickets are pretty expensive, LeLe decideds to try group-buying.
Because the winter holiday tickets are pretty expensive, LeLe decideds to try group-buying.
Input
There are multiple test cases, about 20 cases. The first line of input contains two integers n,m(1≤n,m≤100) . n indicates the number of the students. m indicates how many cinemas have offered group-buying.
For them lines,each line contains two integers ai,bi(1≤ai,bi≤100) , indicating the choices of the group buying cinemas offered which means you can use bi yuan to buy ai tickets in this cinema.
For the
Output
For each case, please help LeLe **choose a cinema** which costs the least money. Output the total money LeLe should pay.
Sample Input
3 22 23 5
Sample Output
4HintLeLe can buy four tickets with four yuan in cinema 1.
Source
BestCoder Round #34
思路:简单贪心
AC代码:
#include <cstdio>#include <cstring>#include <iostream> #include <algorithm>#include <cmath>#define INF 0x3fffffffusing namespace std;struct node {int a, b;}dian[105];int main() {int n, m;while(scanf("%d %d", &n, &m) != EOF) {for(int i = 0; i < m; i++) {scanf("%d %d", &dian[i].a, &dian[i].b);}int ans = INF;for(int i = 0; i<m; i++) {int t = n / dian[i].a;if(n % dian[i].a) t++;if(t * dian[i].b < ans) ans = t * dian[i].b;}printf("%d\n", ans);}return 0;}
Building Blocks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 491 Accepted Submission(s): 106
Problem Description
After enjoying the movie,LeLe went home alone. LeLe decided to build blocks.
LeLe has already builtn piles. He wants to move some blocks to make W consecutive piles with exactly the same height H .
LeLe already put all of his blocks in these piles, which means he can not add any blocks into them. Besides, he can move a block from one pile to another or a new one,but not the position betweens two piles already exists.For instance,after one move,"3 2 3" can become "2 2 4" or "3 2 2 1",but not "3 1 1 3".
You are request to calculate the minimum blocks should LeLe move.
LeLe has already built
LeLe already put all of his blocks in these piles, which means he can not add any blocks into them. Besides, he can move a block from one pile to another or a new one,but not the position betweens two piles already exists.For instance,after one move,"3 2 3" can become "2 2 4" or "3 2 2 1",but not "3 1 1 3".
You are request to calculate the minimum blocks should LeLe move.
Input
There are multiple test cases, about 100 cases.
The first line of input contains three integersn,W,H(1≤n,W,H≤50000) .n indicate n piles blocks.
For the next line ,there aren integers A1,A2,A3,……,An indicate the height of each piles. (1≤Ai≤50000)
The height of a block is 1.
The first line of input contains three integers
For the next line ,there are
The height of a block is 1.
Output
Output the minimum number of blocks should LeLe move.
If there is no solution, output "-1" (without quotes).
If there is no solution, output "-1" (without quotes).
Sample Input
4 3 21 2 3 54 4 41 2 3 4
Sample Output
1-1HintIn first case, LeLe move one block from third pile to first pile.
Source
BestCoder Round #34
这一场真是太爽了,简直无法忍受了,一直错,,,明明想法是好的,每次都有小BUG,我他妈真是醉了,写得真挫,
思路:其实很简单,就是算出长度为W的区间的正数之和n和负数之和,负数之和再取个绝对值得m,取max(n,m)为MIN,再往后扫每一段长度为W的区间,取其中最小值
AC代码:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#define INF 0x7fffffffusing namespace std;typedef long long LL;const int maxn = 50005;LL mu[maxn * 3];LL zhen;LL fu; int main() {int n, W, H;while(scanf("%d%d%d", &n, &W, &H) != EOF) {LL sum = 0;for(int i = W; i < W + n; i++) {scanf("%I64d", &mu[i]);sum += mu[i];}if(sum < LL(H) * W) {printf("-1\n");}else {LL MIN, m = n + W * 2;for(int i = 0; i < W; i++) mu[i] = 0;for(int i = W + n; i < m; i++) mu[i] = 0;zhen = 0; fu = LL(H) * W;MIN = max(zhen, fu);for(int i = W; i < m; i++) {if(mu[i - W] < H) fu -= (H - mu[i - W]);else zhen -= mu[i - W] - H;if(mu[i] < H) fu += (H - mu[i]);else zhen += mu[i] - H;MIN = min(MIN, max(zhen, fu));}printf("%I64d\n", MIN);}}return 0;}
一直让我魂牵梦绕调BUG的代码(尼玛!):
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>#define INF 0x7fffffffusing namespace std;typedef long long LL;const int maxn = 50005;LL mu[maxn * 3];LL zhen;LL fu; int main() { int n, W, H; while(scanf("%d%d%d", &n, &W, &H) != EOF) { LL sum = 0; memset(mu, 0, sizeof(mu)); for(int i = W; i < W + n; i++) { scanf("%I64d", &mu[i]); mu[i] -= H; sum += mu[i];//其实这里可以放上面,我就不用找的这么辛苦了。。。哎。。。代码能力。 } if(sum < 0) {//错误!这里sum值不是判断其小于0,而是判断sum+n*H<W*H, printf("-1\n");//我靠,劳资就是这里被自己误导的, }//写程序真的是要严谨严谨再严谨啊!!!! else { LL MIN, m = n + W * 2; for(int i = 0; i < W; i++) mu[i] -= H; for(int i = W + n; i < m; i++) mu[i] -= H; zhen = 0; fu = LL(H) * W; MIN = max(zhen, fu); for(int i = W; i < m; i++) { if(mu[i - W] < 0) fu -= (-mu[i - W]); else zhen -= mu[i - W]; if(mu[i] < 0) fu += (-mu[i]); else zhen += mu[i]; MIN = min(MIN, max(zhen, fu)); } printf("%I64d\n", MIN); } } return 0;}
0 0
- HDU - 5190 - Go to movies && 5191 - Building Blocks (BC#34 A,B)
- 【CUGBACM14级BC第34场 A】hdu 5190 Go to movies
- BC 34# 1001 Go to movies
- hdu 5190 Go to movies(水)
- HDU 5190-Go to movies
- hdu 5190 Go to movies
- HDU-5190-Go to movies
- BC#34 1002 hdu 5192 Building Blocks
- Building Blocks (hdu 5191)
- HDU 5191 Building Blocks
- hdu 5191 Building Blocks
- hdu 5191 Building Blocks
- hdu 5191-Building Blocks
- HDU 5191 Building Blocks
- BestCoder Round #34 1001 Go to movies
- hdu 5191 Building Blocks(前缀和)
- HDU 5191 Building Blocks(枚举)
- hdu 5191 Building Blocks(模拟,思路)
- 对比苹果表,说说moto360
- javascript教程:console.log 详解
- libevent源码深度剖析七
- [转]C++中sizeof(struct)怎么计算?
- 统计文件中姓名及出现次数的小例子
- HDU - 5190 - Go to movies && 5191 - Building Blocks (BC#34 A,B)
- libevent源码深度剖析六
- 搭建C++集成开发环境
- libevent源码深度剖析五
- (转)nginx源码剖析-红黑树ngx_rbtree_t
- 初探nginx架构
- 次时代引擎技术一览
- libevent源码深度剖析四
- Pow(x, n)