Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
计算每块过道上的次数之和 取最大值,还得注意一下我第一个想法就是,经过一个过道,该过道段就+1,之后取最大段*10;瞄了一下discuss,发现有人先说这个方法了。提交,wa,再看discuss,wa在官方给的第二组数上了。 所以注意一下: 稍微改改就可以了: if(b[i-1]%2==1&&a[i]==b[i-1]+1)||(b[i-1]%2==0&&a[i]==b[i-1]-1) room[i]++; //a是开始的房间,b是结束的房间。 如果是那种直上直下不冲突的,是b[i-1]%2==0&&a[i]==b[i-1]+1 再提交ac 0ms 代码如下作参考: #include<stdio.h> #include<string.h> int room[410],a[410],b[410]; int main() { int t,n,i,j; scanf("%d",&t); while(t--) { memset(room,0,sizeof(room)); scanf("%d",&n); for(i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]); for(i=1;i<=n;i++) { if(a[i]>b[i]) { int tmp=a[i];a[i]=b[i];b[i]=tmp; } for(j=a[i];j<=b[i];j++) room[j]++; if((b[i-1]%2==1&&a[i]==b[i-1]+1)||(b[i-1]%2==0&&a[i]==b[i-1]-1)) room[i]++; } int max=0; for(i=1;i<410;i++) if(room[i]>max) max=room[i]; printf("%d\n",max*10); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator