CSDN博客

img pipopipo

ACM晚上的模拟赛也狂FT

发表于2004/10/11 1:51:00  936人阅读

唉,有心栽花花不开,无心插柳柳成荫呀... F题(PKU1899)居然找了4个小时没找出来一个三个字符的BUG,还是三个人一起看呀...而C题(PKU1886)居然随便写了下,一下就AC了... 太受不了,下次不能这么急中一起看,要分开,且不能5个小时一题,这样死得很惨...最后总共才lijunwei和我一人一题,flybird刚好后面看F,没做出来... 可惜..怪我把BUG放了,然后把他们都定了,没人发现出来..才二题... 下次加油了,我们还是很有机会的,嗯16号,争取:)
  附(PKU1899)2004.10.10的F题正确答案以及8小时人没找出来的3个字符的BUG:

 
发现你的程序问题了
#include <iostream>
#include <fstream>
using namespace std;
int i,j;
bool findit(int up1,int down1,int left1,int right1,
            int up2,int down2,int left2,int right2)
{
    if(down2>=down1&&down2<=up1 && left2>=left1&&left2<=right1){
        return true;
    }
    if(down2>=down1&&down2<=up1 && right2>=left1&&right2<=right1){
        return true;
    }
    if(up2>=down1&&up2<=up1 && left2>=left1&&left2<=right1){
        return true;
    }
    if(up2>=down1&&up2<=up1 && right2>=left1&&right2<=right1){
        return true;
    }
    return false;
}
 
 
 
#include<fstream>
int main(void)
{
//  ifstream cin("test.txt");
    int x,y,n;//1~1000xy,0~100n
    int r[105][3];
    int o[105][5];  //每行第0个表示是否有效
    while(cin>>x>>y){
        // input
        cin>>n;
        if(n == 0){
            cout<<x*y<<"/n";
            continue;
        }
 
        for(i=1;i<=n;i++){
            cin>>r[i][0]>>r[i][1]>>r[i][2];
        }
        //
        for(i=1;i<=n;i++){
            o[i][0] = 0;
        }
        // cal
        int up1,down1,left1,right1;
        for(int i=1;i<=n;i++){
            up1 = r[i][1]+r[i][2];
            down1 = r[i][1]- r[i][2];
            left1 = r[i][0] -r[i][2];
            right1 = r[i][0] + r[i][2];
            //取一圆看与里面的是否相交,相交就把里面的杀了
            for(j=1;j<i;j++){
                if(o[j][0] !=0 ){ //有效,取出判断
                    //查看二个矩形是否相交
                    if(findit(o[j][1],o[j][2],o[j][3],o[j][4],
                        up1,down1,left1,right1)
                        ||findit(up1,down1,left1,right1,o[j][1],o[j][2],o[j][3],
o[j][4])){
                        //合并
                        if(o[j][1]>up1)
                            up1 = o[j][1];
                        if(o[j][2]<down1)
                            down1 = o[j][2];
                        if(o[j][3]<left1)
                            left1 = o[j][3];
                        if(o[j][4]>right1)
                            right1 = o[j][4];
                        o[j][0] = 0;
//*************************************************************************
                       j=0;//BUG处,在将新矩形扩展后,应该从开始处再搜,有可能扩展也会把前面的交了..
//*************************************************************************

                    }
                }
            }
            o[i][0] = 1;
            o[i][1] = up1;
            o[i][2] = down1;
            o[i][3] = left1;
        }
        int all = x*y;
        for(i=1;i<=n;i++){
            if(o[i][0] != 0){
                all =all- (o[i][1]-o[i][2])*(o[i][4]-o[i][3]);
            }
        }
        if(all<0)
            all=0;
        cout<<all<<endl;
    }
 
 
    return 0;
}
 
 
阅读全文
0 0

相关文章推荐

img
取 消
img