hdu 6205 card card card 尺取+超神读入挂

Posted 可是我不配

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 6205 card card card 尺取+超神读入挂相关的知识,希望对你有一定的参考价值。

题没啥好说的 

我就是想把读入挂记录一下

 

 1 #include<bits/stdc++.h>
 2 #define cl(a,b) memset(a,b,sizeof(a))
 3 #define debug(a) cerr<<#a<<"=="<<a<<endl
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int> pii;
 7 
 8 const int maxn=1e6+10;
 9 
10 int n;
11 int a[maxn*2];
12 int b[maxn*2];
13 
14 namespace fastIO {
15     #define BUF_SIZE 100000
16     //fread -> read
17     bool IOerror = 0;
18     inline char nc() {
19         static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
20         if(p1 == pend) {
21             p1 = buf;
22             pend = buf + fread(buf, 1, BUF_SIZE, stdin);
23             if(pend == p1) {
24                 IOerror = 1;
25                 return -1;
26             }
27         }
28         return *p1++;
29     }
30     inline bool blank(char ch) {
31         return ch ==   || ch == \n || ch == \r || ch == \t;
32     }
33     inline void read(int &x) {
34         char ch;
35         while(blank(ch = nc()));
36         if(IOerror)
37             return;
38         for(x = ch - 0; (ch = nc()) >= 0 && ch <= 9; x = x * 10 + ch - 0);
39     }
40     #undef BUF_SIZE
41 };
42 using namespace fastIO;
43 
44 int chiqu(int n)
45 {
46     int sum=0,mx=0,ans=0;
47     for(int l=1,r=1; l<=n&&r<=n;)
48     {
49         if(sum>0) sum+=(a[r]-b[r++]);
50         if(r-l+1>=mx)
51         {
52             mx=r-l+1;
53             ans=l-1;
54         }
55         if(sum<=0) sum-=(a[l]-b[l++]);
56     }
57     return ans;
58 }
59 
60 int main()
61 {
62     while(read(n),!fastIO::IOerror)
63     {
64         for(int i=1; i<=n; i++) read(a[i]);
65         for(int i=1; i<=n; i++) read(b[i]);
66         for(int i=1; i<=n; i++) a[i+n]=a[i],b[i+n]=b[i];
67         int ans=chiqu(2*n);
68 //        debug(ans);
69         printf("%d\n",ans);
70     }
71     return 0;
72 }/*
73 
74 5
75 4 6 2 8 4
76 1 5 7 9 2
77 
78 */

 

以上是关于hdu 6205 card card card 尺取+超神读入挂的主要内容,如果未能解决你的问题,请参考以下文章

HDU 6205 card card card ( 思维 )

2017ICPC沈阳网络赛 HDU 6025 -- card card card(最大子段和)

HDU4876:ZCC loves cards

HDU 1528 Card Game Cheater

hdu 4336 Card Collector

hdu_4336_Card Collector