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. Mininet系列实验(六):Mininet动态改变转发规则实验

    一. 实验目的 熟悉Mininet自定义拓扑脚本的编写:熟悉编写POX脚本动态改变转发规则 二.实验原理 在SDN环境中,控制器可以通过对交换机下发流表操作来控制交换机的转发行为.在本实验中,基于Mi ...

  2. 【Java】 HashMap

    Java HashMap 标签(空格分隔): Java source-code hash-map 总结 HashTable的基本数据结构 Entry的hash与table的长度计算indexFor才能 ...

  3. python pip settools 安装基于源码 gdal安装需要c++相关库

  4. 【Oracle/Java】多表插删数据单多线程比较

    源码下载:https://files.cnblogs.com/files/xiandedanteng/OracleAccessComparison20191117.rar 做这个比较工程初衷是:我在单 ...

  5. nineoldandroids开源库

    Android3.0 推出AnimationAPI ,使用起来比较方便,但是不能再3.0以下版本中使用.nineoldandroids开源库可以在任意版本上使用,官网地址:http://nineold ...

  6. ASP生成JSON数据

    原文地址为:ASP生成JSON数据 < %@LANGUAGE = " VBSCRIPT "  CODEPAGE = " 65001 " % >    ...

  7. osg::PagedLOD example

    int main() { osg::ref_ptr<osgViewer::Viewer> viewer1 = new osgViewer::Viewer; osg::ref_ptr< ...

  8. Qt编写自定义控件56-波浪曲线

    一.前言 波浪曲线控件,其实是之前一个水波进度条控件的一个核心,其实就是利用正弦曲线来生成对应的坐标进行绘制,把这个功能单独提取出来,是为了更详细的研究各种正弦余弦等拓展效果,当时写这个效果的时候,参 ...

  9. Composer更新慢的终极解决方案-转

    转自:http://blog.csdn.net/fishermanmax/article/details/51975692 Packagist 镜像 请各位使用本镜像的同学注意: 本镜像已经依照 co ...

  10. Cas(01)——简介

    Cas的全称是Centeral Authentication Service,是对单点登录SSO(Single Sign On)的一种实现.其由Cas Server和Cas Client两部分组成,C ...