首页 技术 正文
技术 2022年11月9日
0 收藏 601 点赞 2,161 浏览 2230 个字

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 DescriptionAs 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. InputThere 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. OutputFor 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 Input54 6 2 8 41 5 7 9 2 Sample Output4 题意:每一次按顺序从第一排拿一个数字,当得到的数字和小于第二排的“惩罚数”之和时,停止取数。在进行操作之前能够把一、二排对应数字放到数列最后。问最少几次把数字放到最后,最终取得的数字和最大。 思路:按照最大字段和的思路,先把数列扩展两倍,在扫的时候记录最区间左端点,每次更新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 ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,031
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,860