2017 ACM/ICPC Asia Regional Shenyang Online card card card
题意:看后面也应该知道是什么意思了
解法:
我们设置l,r,符合条件就是l=起始点,r=当前点,不符合l=i+1
学习了一下FASTIO
1 #include <iostream> 2 #include <algorithm> 3 #include <set> 4 #include <string> 5 #include <vector> 6 #include <queue> 7 #include <map> 8 #include <stack> 9 #include <list> 10 #include <iomanip> 11 #include <functional> 12 #include <sstream> 13 #include <cstdio> 14 #include <cstring> 15 #include <cmath> 16 #include <cctype> 17 //#define read read() 18 #define edl putchar('\n') 19 #define ll long long 20 #define clr(a,b) memset(a,b,sizeof a) 21 #define rep(i,m,n) for(int i=m ; i<=n ; i++) 22 #define fep(i,n) for(int i=0 ; i<n ; i++) 23 //inline int read{ int x=0;char c=getchar();while(c<'0' || c>'9')c=getchar();while(c>='0' && c<='9'){ x=x*10+c-'0';c=getchar(); }return x;} 24 25 namespace FastIO { 26 const int SIZE = 1 << 16; 27 char buf[SIZE], obuf[SIZE], str[60]; 28 int bi = SIZE, bn = SIZE, opt; 29 int read(char *s) { 30 while (bn) { 31 for (; bi < bn && buf[bi] <= ' '; bi++); 32 if (bi < bn) break; 33 bn = fread(buf, 1, SIZE, stdin); 34 bi = 0; 35 } 36 int sn = 0; 37 while (bn) { 38 for (; bi < bn && buf[bi] > ' '; bi++) s[sn++] = buf[bi]; 39 if (bi < bn) break; 40 bn = fread(buf, 1, SIZE, stdin); 41 bi = 0; 42 } 43 s[sn] = 0; 44 return sn; 45 } 46 bool read(int& x) { 47 int n = read(str), bf; 48 49 if (!n) return 0; 50 int i = 0; if (str[i] == '-') bf = -1, i++; else bf = 1; 51 for (x = 0; i < n; i++) x = x * 10 + str[i] - '0'; 52 if (bf < 0) x = -x; 53 return 1; 54 } 55 }; 56 #define read(x) FastIO::read(x) 57 using namespace std; 58 int X[1234567*2],Y[1234567*2]; 59 const int maxn = 1007; 60 int n, m, mp[maxn][maxn], link[maxn]; 61 bool vis[maxn]; 62 int main() { 63 64 while(read(n)) { 65 for(int i=1;i<=n;i++){ 66 read(X[i]); 67 X[n+i]=X[i]; 68 } 69 for(int i=1;i<=n;i++){ 70 read(Y[i]); 71 Y[i]=X[i]-Y[i]; 72 Y[i+n]=Y[i]; 73 } 74 int sum=0; 75 int ans=0; 76 int index=1; 77 int r=1; 78 int St; 79 int Max=-((1<<31)-1); 80 for(int i=1;i<=2*n;i++){ 81 sum+=X[i]; 82 ans+=Y[i]; 83 if(sum>Max){ 84 Max=sum; 85 St=index; 86 r=i; 87 } 88 if(ans<0){ 89 index=i+1; 90 sum=0; 91 ans=0; 92 if(index>n+1){ 93 break; 94 } 95 } 96 } 97 printf("%d\n",St-1); 98 } 99 return 0; 100 }