标签:tle open 分享 min ref for space get style
http://172.20.6.3/Problem_Show.asp?id=1536
确实不难,找规律的题,开始想复杂了,分了好多情况。
开始为省几个变量加了一大堆max,min,abs代码一下子复杂太多,出力不讨好。也算引以为戒,脑子越学越死了
代码
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 #include<queue> 7 using namespace std; 8 const int maxn=110; 9 int n,m,k,s,x,y,xx,yy; 10 int xx1,xx2,yy1,yy2; 11 int main(){ 12 scanf("%d%d%d%d",&n,&m,&k,&s); 13 scanf("%d%d",&x,&y); 14 int ans=10000000,zz; 15 for(int i=1;i<=m;i++){ 16 scanf("%d%d",&xx,&yy);zz=0; 17 if(xx>x){xx1=x;xx2=xx; yy1=y;yy2=yy;} 18 else {xx1=xx;xx2=x; yy1=yy;yy2=y;} 19 zz=(xx2-xx1)*2; int l=yy1,r=zz+yy1; 20 if(yy2>=l&&yy2<=r){ 21 if(yy2%2!=yy1%2)zz--; 22 } 23 else{ 24 zz+=min(abs(yy2-r),abs(yy2-l)); 25 } 26 ans=min(ans,zz); 27 } 28 if(ans*k+1<=s)printf("%d\n",s-ans*k-1); 29 else printf("-1\n"); 30 return 0; 31 }
标签:tle open 分享 min ref for space get style
原文地址:http://www.cnblogs.com/137shoebills/p/7788188.html