Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

分享一下wa的过程的一些数据和代码(含一组数据)

Posted by 1769157748 at 2019-08-17 10:17:07 on Problem 2002
数据:
4
1 1
2 3
3 2
4 4

difx=Abs(s[i].x-s[j].x);
dify=Abs(s[i].y-s[j].y);
x3=s[i].x+dify;
y3=s[i].y+difx; 
x4=s[j].x+dify;
y4=s[j].y+difx;
(Abs函数其实就是abs,只不过我交abs函数时居然给我报了个ce。。。)通过这两个公式,我是可以根据两个点的坐标,直接推出第3个点的坐标和第4个点的坐标,但是后来才发现菱形也满足这个性质,就wa了,因此就特判是不是菱形即可。

代码:
#include<iostream>
#include<set>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

#define N 1001

struct node{
	int x,y;
	bool operator<(const node &a)const{
		if(a.x!=x) return x<a.x;
		else return y<a.y;
	}
}s[N];
set<node> st;
int Abs(int a){
    return a>0?a:-a; 
}

int main(){
	int n,x3,y3,x4,y4,res,k,a,b,c,difx,dify;
	while(scanf("%d",&n)&&n){
		st.clear();
		res=0;
		for(int i=0;i<n;++i){
			scanf("%d%d",&s[i].x,&s[i].y);
			st.insert(s[i]);
		}
		for(int i=0;i<n;++i){
			for(int j=0;j<n;++j){
				if(j==i) continue;
				difx=Abs(s[i].x-s[j].x);
				dify=Abs(s[i].y-s[j].y);
				x3=s[i].x+dify;
				y3=s[i].y+difx;
				if((s[j].x-s[i].x)*(x3-s[i].x)+(s[j].y-s[i].y)*(y3-s[i].y)!=0)continue;//菱形也满足这个性质,所以需要特判等于90度 
				x4=s[j].x+dify;
				y4=s[j].y+difx; 
				if(st.count(node{x3,y3})&&st.count(node{x4,y4})) {
					if(s[i].x!=s[j].x&&s[i].y!=s[j].y) {
						if(s[j].x-s[i].x!=s[j].y-s[i].y)res+=2;
					}
					else res++;
//					cout<<i<<" "<<j<<" "<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<" "<<res<<endl; 
				}
			}
		}
		cout<<res/4<<endl; 
	}

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator