ACM PKU 1468 Rectangles 暴力搜索

http://acm.pku.edu.cn/JudgeOnline/problem?id=1468
时间限制竟然是50000ms ,而n<=5000, 直接搜索时间复杂度是O(n^2) ,完全可能符合条件,直接暴力解决.

Source

Problem Id:1468  User Id:lnmm
Memory:144K  Time:2718MS
Language:C++  Result:Accepted
 1#include"stdio.h"
 2struct rec{
 3int    x1,x2,y1,y2;
 4}
rec [5001];
 5
 6bool cover(int i,int j)
 7{
 8    if((rec[i].x1>=rec[j].x1)&&(rec[i].x2<=rec[j].x2)&&(rec[i].y1>=rec[j].y1)&&(rec[i].y2<=rec[j].y2))return true;
 9    else return false;
10}

11
12void main()
13{
14    int n,i,k,j;
15    while(scanf("%d",&n)!=EOF)
16    {
17        k=0;
18        for(i=1;i<=n;i++)
19            scanf("%d%d%d%d",&rec[i].x1,&rec[i].x2,&rec[i].y1,&rec[i].y2);
20        for(i=1;i<=n;i++)
21            for(j=1;j<=n;j++)
22                if(i!=j&&cover(i,j)){k++;break; }
23        printf("%d\n",k);
24        
25               
26    }

27
28}

29

posted on 2007-09-16 03:33 流牛ζ木马 阅读(757) 评论(2)  编辑 收藏 引用

评论

# re: ACM PKU 1468 Rectangles 暴力搜索 2008-01-20 20:03 Pope

for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(i!=j&&cover(i,j)) {
k++;break;
}
请问为什么要break?
  回复  更多评论   

# re: ACM PKU 1468 Rectangles 暴力搜索 2010-01-06 16:42 CRonaldo

@Pope
既然已经知道被覆盖,就没有必要继续循环下去了。  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2010年1月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

公告

MY Email/MSN :mars1021@163.com QQ : 27402040 流牛ζ木马

常用链接

留言簿(6)

随笔档案

相册

搜索

最新随笔

最新评论

阅读排行榜

评论排行榜