Problem 1001 2 2147483647 2147483647

2014329600047 | 2015-02-14 22:40:52Author
我去,这组数据有什么问题?
dlhham | 2015-02-14 23:19:41# 1
RE:2 2147483647 2147483647
3 2147483646 3 0 int会挂这组
chocobo | 2015-02-15 00:28:56# 2
RE:2 2147483647 2147483647
#include int main() { long kiss=0,people[200],i,j; long t,n,count=1; long mid=1; while( scanf("%ld",&n)!=EOF ) { if(n==1) // if n=1 { printf("Case #%ld: -1\n",count); count++; continue; } for(i=1;i<=n;i++) //input scanf("%ld",&people[i]); for(i=1;ipeople[j]) { t=people[i]; people[i]=people[j]; people[j]=t; } // no need to cal left and right // for( i=n; people[i]==people[i-1] ; i--) //cal first left // left++; // for( i=1; people[i]==people[i+1]; i++ ) //first mid // mid++; // for(j=i+mid;people[j]=people[j+1]; j++) //first right // right++; people[0]=people[n]; //first left_number people[n+1]=people[1]; for(i=1;i<=n;i++) { while(people[i]==people[i+1]) { mid++; i++; } if(mid==n || people[1]==people[n]) { kiss=-1; break; } else if(people[i]+people[i-mid]<0 && people[i]-2147483647+people[i-mid]==people[i+1]) kiss+=mid; else if(people[i]+people[i-mid]>0 && people[i]+people[i-mid]==people[i+1]) //over flow kiss+=mid; mid=1; } printf("Case #%ld: %ld\n",count,kiss); // for(i=0;i<=n+1;i++) //test // printf(" %ld ",people[i]); kiss=0; count++; } return 0; }
chocobo | 2015-02-15 00:31:16# 3
RE:2 2147483647 2147483647
啊,对不起,我以为是提交代码的地方。 判断是否溢出(加为负数)再处理可以?我去提交看看。 对不起,不能贴代码的话请帮删除,谢谢。