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. 类Calendar

    /* * Calendar类概述及其方法 * * Calendar类概述 * Calendar类是一个抽象类,它为特定瞬间与一组诸如YEAR.MONTH.DAY_OF_MONTH.HOUR等 * 日历 ...

  2. JSP不支持EL表达式的解决方案

    EL的全称是Expression Language.1.在默认情况下,Servlet 2.3 / JSP 1.2是不支持EL表达式的,而Servlet 2.4 / JSP 2.0支持. servlet ...

  3. python正则表达式整理

    正则表达式在处理字符串时很大的作用,爬虫中也经常用到,下面就将一些常用正则表达式做一整理记录,方便以后查看. ^d   表示匹配以d开头的字符串 .      表示匹配任意字符串 *     表示前面 ...

  4. C#MessageBox 自动关闭窗口

    1:MessageBox弹出的模式窗口会先阻塞掉它的父级线程.所以我们可以考虑在MessageBox前先增加一个用于"杀"掉MessageBox窗口的线程.因为需要在规定时间内&q ...

  5. [2019杭电多校第七场][hdu6655]Just Repeat

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6655 题意是说两个人都有一些带有颜色的牌,两人轮流出牌,但是不能出对面出过的颜色的牌,最后谁不能出牌谁 ...

  6. 使用IntelliJ IDEA配置Tomcat(详细操作)

    一,下载Tomcat 1.进入官网Http://tomcat.apache.org/,选择download,下载所需要的Tomcat版本.(注意:最好下载Tomcat 7 或者Tomcat 8 因为最 ...

  7. 小白学Python(13)——pyecharts 绘制 柱状图/条形图 Bar

    Bar-基本示例 from example.commons import Faker from pyecharts import options as opts from pyecharts.char ...

  8. FZUOJ-2273 Triangles

     Problem 2273 Triangles Accept: 109    Submit: 360 Time Limit: 1000 mSec    Memory Limit : 262144 KB ...

  9. 如何在CentOS 7上安装Yarn

    Yarn是与npm兼容的JavaScript软件包管理器,可帮助自动化安装,更新,配置和删除npm软件包的过程. 它的创建是为了解决npm的一系列问题,例如通过并行化操作并减少与网络连接有关的错误来加 ...

  10. Elasticsearch7.X 入门学习第三课笔记----search api学习(URI Search)

    原文:Elasticsearch7.X 入门学习第三课笔记----search api学习(URI Search) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出 ...