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. JAVA爬虫对font-face字体反爬虫解密

    1.参考博客          https://www.jianshu.com/p/9975de57b0ce          https://blog.csdn.net/litang199612/a ...

  2. Lasso回归的坐标下降法推导

    目标函数 Lasso相当于带有L1正则化项的线性回归.先看下目标函数:RSS(w)+λ∥w∥1=∑Ni=0(yi−∑Dj=0wjhj(xi))2+λ∑Dj=0∣wj∣RSS(w)+λ∥w∥1=∑i=0 ...

  3. Tomcat监听shutdown释放数据库连接池

    开发时因为更新代码,频繁重启Tomcat,遇到一个问题:在执行shutdown脚本后,Tomcat进程没有关闭依然存在(但是HTTP服务已经停止),需要手动执行kill命令才行.查了一些资料结合经验, ...

  4. 批量删除Maven 仓库未下载成功.lastupdate 的文件

    Windows: @echo off echo 开始... for /f "delims=" %%i in ('dir /b /s "./*lastUpdated&quo ...

  5. 【417】一条语句编译并执行C语言

    参考:shell学习笔记(1)Linux下在一行执行多条命令 要实现在一行执行多条Linux命令,分三种情况: 1.&& 举例: lpr /tmp/t2 && rm / ...

  6. pyenv管理python版本

    一.介绍 pyenv 是 Python 版本管理工具. pyenv 可以改变全局的 Python 版本,安装多个版本的 Python, 设置目录级别的 Python 版本,还能创建和管理 virtua ...

  7. (十一)使用Jconsole监控线程

    一.案例 监控线程情况,包括阻塞.死循环等 1.1 代码如下,下述代码共有三个线程,Main.mythread01.mythread02线程,其中mythread01线程为死循环.mythread02 ...

  8. iis启动异常 0x80072749

    错误提示: “/”应用程序中的服务器错误. 无法向会话状态服务器发出会话状态请求.请确保 ASP.NET State Service (ASP.NET 状态服务)已启动,并且客户端端口与服务器端口相同 ...

  9. iOS-UITextField和UITextView隐藏键盘

    UITextField和UITextView隐藏键盘 71 views, IOS DEV, by admin. self._textField.returnKeyType=UIReturnKeyDon ...

  10. (一)Asp.net web api中的坑-【找不到与请求 URI匹配的 HTTP 资源】

    在.net下,创建一个HTTP服务,有很多方案,比较老ashx,一般处理程序(HttpHandler), Web Service SOAP协议的,数据格式是XML,HTTP协议         WCF ...