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

题没啥好说的 

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

 

update(2017-10-03)

把读入挂加上了调试 

 

 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 #define JUDGE
15 
16 #ifdef DEBUG
17 inline bool read(int &ret)
18 {
19     if(scanf("%d",&ret)==EOF) return false;
20     return true;
21 }
22 #endif  DEBUG
23 
24 #ifdef JUDGE
25 namespace fastIO {
26     #define BUF_SIZE 100000
27     //fread -> read
28     bool IOerror = 0;
29     inline char nc() {
30         static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
31         if(p1 == pend) {
32             p1 = buf;
33             pend = buf + fread(buf, 1, BUF_SIZE, stdin);
34             if(pend == p1) {
35                 IOerror = 1;
36                 return -1;
37             }
38         }
39         return *p1++;
40     }
41     inline bool blank(char ch) {
42         return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
43     }
44     inline bool read(int &x) {
45         char ch;
46         while(blank(ch = nc()));
47         if(IOerror)
48             return false;
49         for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
50         return true;
51     }
52     #undef BUF_SIZE
53 };
54 using namespace fastIO;
55 #endif JUDGE
56 
57 int chiqu(int n)
58 {
59     int sum=0,mx=0,ans=0;
60     for(int l=1,r=1; l<=n&&r<=n;)
61     {
62         if(sum>0) sum+=(a[r]-b[r++]);
63         if(r-l+1>=mx)
64         {
65             mx=r-l+1;
66             ans=l-1;
67         }
68         if(sum<=0) sum-=(a[l]-b[l++]);
69     }
70     return ans;
71 }
72 
73 int main()
74 {
75     while(read(n))
76     {
77         for(int i=1; i<=n; i++) read(a[i]);
78         for(int i=1; i<=n; i++) read(b[i]);
79         for(int i=1; i<=n; i++) a[i+n]=a[i],b[i+n]=b[i];
80         int ans=chiqu(2*n);
81 //        debug(ans);
82         printf("%d\n",ans);
83     }
84     return 0;
85 }/*
86 
87 5
88 4 6 2 8 4
89 1 5 7 9 2
90 
91 */

 

posted @ 2017-09-10 22:33  良将ℓ  阅读(226)  评论(0编辑  收藏  举报