card card card HDU - 6205
One day, MJF takes a stack of cards and talks to him: let's play a game and if you win, you can get all these cards. MJF randomly assigns these cards into nn heaps, arranges in a row, and sets a value on each heap, which is called "penalty value".
Before the game starts, WYJ can move the foremost heap to the end any times.
After that, WYJ takes the heap of cards one by one, each time he needs to move all cards of the current heap to his hands and face them up, then he turns over some cards and the number of cards he turned is equal to the penaltyvaluepenaltyvalue.
If at one moment, the number of cards he holds which are face-up is less than the penaltyvaluepenaltyvalue, then the game ends. And WYJ can get all the cards in his hands (both face-up and face-down).
Your task is to help WYJ maximize the number of cards he can get in the end.So he needs to decide how many heaps that he should move to the end before the game starts. Can you help him find the answer?
MJF also guarantees that the sum of all "penalty value" is exactly equal to the number of all cards.
InputThere are about 1010 test cases ending up with EOF.
For each test case:
the first line is an integer nn (1≤n≤1061≤n≤106), denoting nn heaps of cards;
next line contains nn integers, the iithth integer aiai (0≤ai≤10000≤ai≤1000) denoting there areaiai cards in iithth heap;
then the third line also contains nn integers, the iithth integer bibi (1≤bi≤10001≤bi≤1000) denoting the "penalty value" of iithth heap is bibi.
OutputFor each test case, print only an integer, denoting the number of piles WYJ needs to move before the game starts. If there are multiple solutions, print the smallest one.
Sample Input
5
4 6 2 8 4
1 5 7 9 2
Sample Output
4
Hint
[pre]
For the sample input: + If WYJ doesn't move the cards pile, when the game starts the state of cards is:
4 6 2 8 4
1 5 7 9 2
WYJ can take the first three piles of cards, and during the process, the number of face-up cards is 4-1+6-5+2-7. Then he can't pay the the "penalty value" of the third pile, the game ends. WYJ will get 12 cards.
+ If WYJ move the first four piles of cards to the end, when the game starts the state of cards is:
4 4 6 2 8
2 1 5 7 9
WYJ can take all the five piles of cards, and during the process, the number of face-up cards is 4-2+4-1+6-5+2-7+8-9. Then he takes all cards, the game ends. WYJ will get 24 cards. It can be improved that the answer is 4. **huge input, please use fastIO.**
[/pre] 给你两个数组,数组的元素和相等 让你将a[i]-b[i]的值的和最大
其实只要找到最后一段(a[i]-b[i])和小于0的点就行了 下面上代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[],b[];
int main() {
int n;
while(scanf("%d",&n)!=EOF){
for (int i= ;i<n ;i++ )
scanf("%d",&a[i]);
for (int i= ;i<n ;i++)
scanf("%d",&b[i]);
int sum=,ans=;
for (int i= ;i<n ;i++ ){
sum+=(a[i]-b[i]);
if (sum<) {
ans=i+;
sum=;
}
}
printf("%d\n",ans);
}
return ;
}
card card card HDU - 6205的更多相关文章
- 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)
[BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...
- 【题解】P3129高低卡(白金)High Card Low Card
[题解][P3129 USACO15DEC]高低卡(白金)High Card Low Card (Platinum) 考虑贪心. 枚举在第几局改变规则,在改变规则之前,尽量出比它大的最小的牌,在改变规 ...
- hdu 6205 card card card 尺取法
card card card Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)
card card card Time Limit: 8000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 6205 card card card
https://vjudge.net/contest/184514#problem/L题意:排成一行的一堆牌,每堆牌都有一定数量的牌,然后每堆牌对应有一个惩罚值.一开始所有的牌都是正面向下的,并且在游 ...
- HDU 6205 (模拟) card card card
题目链接 Problem Description As a fan of Doudizhu, WYJ likes collecting playing cards very much. One day ...
- hdu 6205 card card card 最大子段和
#include<iostream> #include<deque> #include<memory.h> #include<stdio.h> #inc ...
- HDU 6205 card card card ( 思维 )
题意 : 给定两个序列 a 和 b ,保证 a 数列的和 == b数列的和,从头到尾考虑 (a[i] - b[i]) 的前缀和,直到前缀和为负数则无法进行下去,所得的便是a[1~i]的和,现在有一个操 ...
- hdu 6205: card card card【输入挂】
题目链接 感谢 http://blog.csdn.net/txgang/article/details/77568491 以下供参考 getchar读入法 2683MS FastIO法 MX=1e2 ...
随机推荐
- BZOJ 2743: [HEOI2012]采花 [树状数组 | 主席树]
题意: 查询区间中出现次数$>2$的颜色个数 一眼主席树,区间中$l \le last[i] \le r$的个数减去$l \le last[last[i]] \le r$的个数,搞两颗主席树来做 ...
- FileBeat安装配置
在ELK中因为logstash是在jvm上跑的,资源消耗比较大,对机器的要求比较高.而Filebeat是一个轻量级的logstash-forwarder,在服务器上安装后,Filebeat可以监控日志 ...
- python怎么实现数组增加一行或多行
对数组增加一行或一列很简单,网上一搜一大把的事例.比如增加一行或一列: import numpy as np a = np.array([[1, 2, 3]]) row = a[0] col = a[ ...
- Angular+ionic2+Echarts 实现图形制作,以饼图为例
step1:添加插件echart; npm install echarts --save package.json文件中会在dependencies中添加echarts,如下图: step2:运行cm ...
- HDU 3001(状态压缩dp)
状态压缩dp的第一题! 题意:Mr ACMer想要进行一次旅行,他决定访问n座城市.Mr ACMer 可以从任意城市出发,必须访问所有的城市至少一次,并且任何一个城市访问的次数不能超过2次.n座城市间 ...
- 请小心使用 ng-repeat 中的 $index
自己自学的时候,遇到$index不知道它是如何使用的,所以上网搜了一下,发现了这个关于使用$index可能会出现的一个小BUG,和大家分享一下 PS:我是小白,欢迎指正,非常感谢! 以下是全文: &q ...
- 【学习笔记】Hibernate关联映射(Y2-1-6)
Hibernate关联映射 关联映射就是将关联关系映射到数据库里,在对象模型中就是一个或多个引用. 1.单向多对一关联 准备数据库 部门表和员工表 其中部门表有两列 部门编号和名称 员工表有三列 员工 ...
- 二叉排序树、平衡二叉树、B树&B+树、红黑树的设计动机、缺陷与应用场景
之前面试时曾被问到"如果实现操作系统的线程调度应该采用什么数据结构?",因为我看过ucore的源码,知道ucore是采用斜堆的方式实现的,可以做到O(n)的插入.O(1)的查找.我 ...
- 17_8_9 Spring 注入
1 Spring 的 Bean 的属性注入: 构造方法的方式注入属性: <!-- 第一种:构造方法的方式 --> <bean id="car" class=&qu ...
- 2015四川省acm B题
Carries frog has n integers a1,a2,-,an, and she wants to add them pairwise. Unfortunately, frog is s ...