card card card

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

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
 
题意:每一次按顺序从第一排拿一个数字,当得到的数字和小于第二排的“惩罚数”之和时,停止取数。在进行操作之前能够把一、二排对应数字放到数列最后。问最少几次把数字放到最后,最终取得的数字和最大。
 
思路:按照最大字段和的思路,先把数列扩展两倍,在扫的时候记录最区间左端点,每次更新a数列区间和时记录最优解的左端点,输出即可。
 
AC代码:
 #include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int MAXN=2e6+;
const int INF=1e9+;
int a[MAXN],b[MAXN],c[MAXN];
int min(int a, int b)
{
return (a>b)?b:a;
}
int main()
{
int n;
while(~scanf("%d", &n))
{
for(int i=;i<n;i++){
scanf("%d", &a[i]);
a[i+n]=a[i];
}
for(int i=;i<n;i++){
scanf("%d", &b[i]);
c[i]=a[i]-b[i];
c[i+n]=c[i];
}
int p=,res=-INF;
int sum=,suma=;
int l=;
for(int i=;i<*n;i++){
sum+=c[i];
suma+=a[i];
if(suma>res)
{
res=suma;
p=l;
}
if(sum<)
{
sum=;
suma=;
l=i+;
if(l>=n) break;
}
}
printf("%d\n", p);
} return ;
}

2017ICPC沈阳网络赛 HDU 6205 -- card card card(最大子段和)的更多相关文章

  1. 2017ICPC沈阳网络赛 HDU 6201 -- transaction transaction transaction(树上dp)

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  2. 2018 ICPC 沈阳网络赛

    2018 ICPC 沈阳网络赛 Call of Accepted 题目描述:求一个算式的最大值与最小值. solution 按普通算式计算方法做,只不过要同时记住最大值和最小值而已. Convex H ...

  3. ccpc 网络赛 hdu 6155

    # ccpc 网络赛 hdu 6155(矩阵乘法 + 线段树) 题意: 给出 01 串,要么询问某个区间内不同的 01 子序列数量,要么把区间翻转. 叉姐的题解: 先考虑怎么算 \(s_1, s_2, ...

  4. 沈阳网络赛 F - 上下界网络流

    "Oh, There is a bipartite graph.""Make it Fantastic." X wants to check whether a ...

  5. HDU 6205 2017沈阳网络赛 思维题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6205 题意:给你n堆牌,原本每一堆的所有牌(a[i]张)默认向下,每次从第一堆开始,将固定个数的牌(b ...

  6. HDU 6200 2017沈阳网络赛 树上区间更新,求和

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6200 题意:给个图,有2种操作,一种是加一条无向边,二是查询u,v之间必须有的边的条数,所谓必须有的边 ...

  7. HDU 6199 2017沈阳网络赛 DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6199 题意:n堆石子,Alice和Bob来做游戏,一个人选择取K堆那么另外一个人就必须取k堆或者k+1 ...

  8. HDU 6203 2017沈阳网络赛 LCA,DFS+树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6203 题意:n+1 个点 n 条边的树(点标号 0 ~ n),有若干个点无法通行,导致 p 组 U V ...

  9. HDU 6198 2017沈阳网络赛 线形递推

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6198 题意:给出一个数k,问用k个斐波那契数相加,得不到的数最小是几. 解法:先暴力打表看看有没有规律 ...

随机推荐

  1. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_08 转换流_1_字符编码和字符集

     

  2. Matplotlib字体大小设置

    参考:https://blog.csdn.net/henkekao/article/details/72871882 ax = plt.subplot(111) # 设置刻度字体大小 plt.xtic ...

  3. PMBOK

    项目章程的内容1. 基于项目干系人的需求和期望提出的要求.2. 项目必须满足的业务要求或产品需求.3. 项目的目的或项目立项的理由.4. 委派的项目经理及项目经理的权限级别.5. 概要的里程碑进度计划 ...

  4. android:为ListView 添加自定义头部和尾部,上拉主动加载 .(引)

    1.加头尾部 (1)定自义一个xml布局 my_headview.xml 在Activity类里找到这个自定义布局,并添加到头部 LinearLayout  hearderViewLayout = ( ...

  5. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

    今天执行mysql操作的时候出现了错误:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run ...

  6. 爬楼梯问题,yield学习总结

    问题起源: 一个人爬楼梯,一步可以迈一级,二级,如果楼梯有N级,要求编写程序,求总共有多少种走法. 简单的一个递归思想,只要爬到了N-1层,或者爬到N-2层,则认定下一步只有一种走法.所以再去找寻N- ...

  7. js导入外部文件

  8. 简单DP入门(一) 数字三角形

    数字三角形

  9. 006/搭建fabric(二)

    准备vmware虚拟机,并安装完ubuntu系统后.继续搭建fabric运行环境... 0.打开终端,切换root身份.目的:后续操作即可不用sudo... 右键->open Terminal- ...

  10. 2019寒假作业一:PTA7-1 打印沙漏

    - 打印沙漏 ( 分) 本题要求你写个程序把给定的符号打印成沙漏的形状.例如给定17个“*”,要求按下列格式打印 ***** *** * *** ***** 所谓“沙漏形状”,是指每行输出奇数个符号: ...