标签:struct getch i++ char str ffffff 比赛 start har
应该是做麻烦了,一开始还没A(幸好上一次比赛水惨了)
1 #include<bits/stdc++.h> 2 #define lowbit(x) x&(-x) 3 #define LL long long 4 #define N 200005 5 #define M 1000005 6 #define mod 2147483648LL 7 #define inf 0x7ffffffff 8 using namespace std; 9 inline int ra() 10 { 11 int x=0,f=1; char ch=getchar(); 12 while (ch<‘0‘ || ch>‘9‘){if (ch==‘-‘) f=-1; ch=getchar();} 13 while (ch>=‘0‘ && ch<=‘9‘){x=x*10+ch-‘0‘; ch=getchar();} 14 return x*f; 15 } 16 int a[1005]; 17 struct node{ 18 int x,y; 19 }ans[1005]; 20 int cnt; 21 int main() 22 { 23 int n=ra(),start=1; 24 bool flag=0; 25 for (int i=1; i<=n; i++) 26 { 27 int x=ra(); 28 if (x!=0) a[i]=x,flag=1; 29 } 30 if (!flag) 31 { 32 cout<<"NO"; 33 return 0; 34 } 35 cout<<"YES"<<endl; 36 if (a[1]==0) 37 { 38 for (int i=1; i<=n; i++) 39 if (a[i]!=0) 40 { 41 for (int j=i+1; j<=n; j++) 42 if (a[j]!=0 || j==n) 43 { 44 ans[++cnt].x=1; 45 ans[cnt].y=j-1; 46 start=j; 47 break; 48 } 49 break; 50 } 51 int last=start; 52 for (int i=last; i<=n; i++) 53 { 54 if (i==n && a[i]==0) 55 ans[cnt].y=n; 56 if (a[i]!=0) 57 { 58 ans[++cnt].x=start; 59 ans[cnt].y=i; 60 start=i+1; 61 } 62 } 63 } 64 else 65 { 66 int last=start; 67 for (int i=last; i<=n; i++) 68 { 69 if (i==n && a[i]==0) 70 ans[cnt].y=n; 71 if (a[i]!=0) 72 { 73 ans[++cnt].x=start; 74 ans[cnt].y=i; 75 start=i+1; 76 } 77 } 78 } 79 cout<<cnt<<endl; 80 for (int i=1; i<=cnt; i++) 81 cout<<ans[i].x<<" "<<ans[i].y<<endl; 82 return 0; 83 }
cf754 A. Lesha and array splitting
标签:struct getch i++ char str ffffff 比赛 start har
原文地址:http://www.cnblogs.com/ccd2333/p/6261963.html