card card card

Time Limit: 8000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1774    Accepted Submission(s): 792

Problem Description
As a fan of Doudizhu, WYJ likes collecting playing cards very much. 
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 n 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 penaltyvalue.
If at one moment, the number of cards he holds which are face-up is less than the penaltyvalue, 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.
 
Input
There are about 10 test cases ending up with EOF.
For each test case:
the first line is an integer n (1≤n≤106), denoting n heaps of cards;
next line contains n integers, the ith integer ai (0≤ai≤1000) denoting there are ai cards in ith heap;
then the third line also contains n integers, the ith integer bi (1≤bi≤1000) denoting the "penalty value" of ith heap is bi.
 
Output
For 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.**

题意:给定一些num以及这些num的value,我们每次都可以把最开头的数字挪到末位去,然后取数字的规则就是拿掉这个数字之后,如果value之和小于num之和,就可以继续取。问我们至少需要挪多长次,可以取最多的num。
题解:既然只能顺序取,那么所有的情况可以把原序列倍增一边之后去遍历所有的情况,由于数据比较大,用尺取法的思想跑一遍就好(需要处理一点细节) 。
ac代码:
#include <cstdio>
#include <iostream>
using namespace std;
int num[];
int v[];
int Scan()
{ // 输入外挂
int res = , flag = ;
char ch;
if ((ch = getchar()) == '-')
{
flag = ;
}
else if(ch >= '' && ch <= '')
{
res = ch - '';
}
while ((ch = getchar()) >= '' && ch <= '')
{
res = res * + (ch - '');
}
return flag ? -res : res;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
{
num[i]=Scan();
num[i+n]=num[i];
}
//cout<<num[6]<<endl;
for(int i=;i<=n;i++)
{
v[i]=Scan();
v[i+n]=v[i];
}
int mx=-;
int ret=;
int l;
int r;
int sumn,sumv,len;
l=r=len=;
sumn=num[l];
sumv=v[l];
while(l<=n)
{
// 回退?
while(sumn < sumv && l<r)
{
len--;
sumn-=num[r];
sumv-=v[r];
r--;
}
while(len<n && sumn >= sumv)
{
r++;
sumn+=num[r];
sumv+=v[r];
len++;
}
// cout<<r<<' '<<sumn<<endl;
if(sumn > mx)
{
mx=sumn;
ret=l-;
}
//while( sumn <= sumv)
sumn-=num[l];
sumv-=v[l];
l++;
len--;
}
//cout<<mx<<endl;
cout<<ret<<endl;
} return ;
}

hdu 6205 card card card 尺取法的更多相关文章

  1. 2017ACM暑期多校联合训练 - Team 6 1008 HDU 6103 Kirinriki (模拟 尺取法)

    题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B= ...

  2. HDU 5358 First One 数学+尺取法

    多校的题,摆明了数学题,但是没想出来,蠢爆了,之前算了半天的s[i][j]的和,其实是积.其实比赛的时候我连log(s[i][j])+1是s[i][j]的位数都没看出来,说出来都丢人. 知道了这个之后 ...

  3. hdu 4737 A Bit Fun 尺取法

    A Bit Fun Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  4. HDU - 6205 card card card (尺取法)

    题意:有n堆牌,ai表示每堆牌的牌数,bi表示每堆牌的penaltyvalue,操作开始前,可以重复进行将第一堆牌挪到最后一堆这一操作.然后,对于挪完后的牌,从第一堆开始,依次取.对于每一堆牌,首先将 ...

  5. 818E - Card Game Again(尺取法)

    818E - Card Game Again 题意 给出一个数列,选择连续的一段使得这些数字的乘积是 k 的倍数,问合法的方案数. 分析 尺取法.设 num 为连续的数的乘积,只要对于 k 的每个素因 ...

  6. HDU 6205(尺取法)2017 ACM/ICPC Asia Regional Shenyang Online

    题目链接 emmmm...思路是群里群巨聊天讲这题是用尺取法.....emmm然后就没难度了,不过时间上3000多,有点.....盗了个低配本的读入挂发现就降到2800左右, 翻了下,发现神犇Clar ...

  7. hdu 5510 Bazinga KMP+尺取法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5510 题意:至多50组数据,每组数据至多500个字符串,每个字符串的长度最长为2000.问最大的下标( ...

  8. 【BZOJ4391】[Usaco2015 dec]High Card Low Card(贪心)

    [BZOJ4391][Usaco2015 dec]High Card Low Card(贪心) 题面 BZOJ 题解 预处理前缀后缀的结果,中间找个地方合并就好了. #include<iostr ...

  9. HDU 6103 Kirinriki(尺取法)

    http://acm.hdu.edu.cn/showproblem.php?pid=6103 题意: 给出一个字符串,在其中找两串互不重叠的子串,计算它们之间的dis值,要求dis值小于等于m,求能选 ...

随机推荐

  1. git 和conding.net 超详细超简单安装

    在做一下操作前,希望你能知道 1.什么是git? 可以参考https://blog.csdn.net/a909301740/article/details/81636662 如果还想多了解一下还可以参 ...

  2. Git的概念和基本使用

    概念篇 1. Git简介: 鉴于有些同学可能还不知道Git是什么,我首先对Git做个简短的介绍.Git就是类似于svn的一个版本控制工具,他其实和hg更像一些,hg也是一个分布式版本控制工具,可以说g ...

  3. c语言复杂申明解释程序

    c语言复杂声明的解释 目标:分析一个将c语言复杂申明解释为英语的一个程序 首先介绍一种简单的读声明的方法,来源网络 1.右左法则 从标识符开始(或者最内层的结构,如果不存在标识符的话,通常出现于函数指 ...

  4. 超详细Qt5.9.5移植攻略

    本文就来介绍下如何将Qt5.9.5移植到ARM开发板上. 以imx6开发板为例,使用Ubuntu14.04虚拟机作为移植环境. 准备工作 1.主机环境:Ubuntu14.04: 开发板:启扬IAC-I ...

  5. poj2456

    Aggressive cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 24979   Accepted: 11594 ...

  6. ThinkPhp5 mongodb 使用自定义objectID出错解决

    在Tp5中使用mongodb 使用自定义ObjectId时报错:Cannot use object of type MongoDB\\BSON\\ObjectID as array 查询源码发现在to ...

  7. 阶段5 3.微服务项目【学成在线】_day18 用户授权_05-方法授权-方法授权测试

    这是我们课程的服务里面 加了授权的方法 重启课程管理的服务 首先需要登陆 在redis复制token 访问课程列表 用最新复制的令牌 最新token可以 调用teachplan方法 调用 一个没加注解 ...

  8. MapReduce\Tez\Storm\Spark四个框架的异同

    1) MapReduce:是一种离线计算框架,将一个算法抽象成Map和Reduce两个阶段进行 处理,非常适合数据密集型计算. 2) Spark:MapReduce计算框架不适合迭代计算和交互式计算, ...

  9. 过滤emoji表情的方法

    public static function replaceEmoji($str) { $str = preg_replace_callback( '/./u', function (array $m ...

  10. zabbix3.4配置windowsAD登录

    转载自:[https://zabbix.com/documentation/3.4/zh/manual/web_interface/frontend_sections/administration/a ...