• card card card HDU


    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 nn 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 penaltyvaluepenaltyvalue. 
    If at one moment, the number of cards he holds which are face-up is less than the penaltyvaluepenaltyvalue, 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 1010 test cases ending up with EOF. 
    For each test case: 
    the first line is an integer nn (1n1061≤n≤106), denoting nn heaps of cards; 
    next line contains nn integers, the iithth integer aiai (0ai10000≤ai≤1000) denoting there areaiai cards in iithth heap; 
    then the third line also contains nn integers, the iithth integer bibi (1bi10001≤bi≤1000) denoting the "penalty value" of iithth heap is bibi. 
    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 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.**
    [/pre]
    
            
     
    给你两个数组,数组的元素和相等

    让你将a[i]-b[i]的值的和最大
    其实只要找到最后一段(a[i]-b[i])和小于0的点就行了


    下面上代码

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<cmath>
     4 #include<algorithm>
     5 using namespace std;
     6 int a[1000010],b[1000010];
     7 int main() {
     8     int n;
     9     while(scanf("%d",&n)!=EOF){
    10         for (int i=0 ;i<n ;i++ )
    11             scanf("%d",&a[i]);
    12         for (int i=0 ;i<n ;i++)
    13             scanf("%d",&b[i]);
    14         int sum=0,ans=0;
    15         for (int i=0 ;i<n ;i++ ){
    16             sum+=(a[i]-b[i]);
    17             if (sum<0) {
    18                 ans=i+1;
    19                 sum=0;
    20             }
    21         }
    22         printf("%d
    ",ans);
    23     }
    24     return 0;
    25 }
  • 相关阅读:
    上网助手(集成ipv6)windows版
    c# 串口编程
    test blog
    用于主题检测的临时日志(d020b283408c4bc68872f97ee237b663 3bfe001a32de4114a6b44005b770f6d7)
    OpenGL概述 陌陌
    [转载][转帖]谈谈我对攻读计算机研究生的看法。。。大牛的文章,见解精深独到
    滚动值的兼容问题
    js小练习去掉指定的字符组成一句话输出
    马虎将classname加到了id属性中,造成报错
    锋利的jquery读书笔记(一)
  • 原文地址:https://www.cnblogs.com/qldabiaoge/p/8513304.html
Copyright © 2020-2023  润新知