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 MIKASA114514 at 2022-05-26 22:22:31 on Problem 1328
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
using namespace std;
struct ra
{
	double p1;
	double p2;
	double x;
	double y;
}a[1000];
int cmp(ra a, ra b)
{
	     return a.p1 < b.p1;//对小岛构成的圆与x轴的左交点进行从小到大的排序
}
int main()
{
	int x, y;
	int n, d;
	int count = 0;
	int ans = 1;
	int flag = 0;
	while (scanf_s("%d %d", &n, &d))
	{
		if (n == 0 && d == 0)
		{
			return 0;
		}
		
		for (int i = 0; i < n; i++)
		{
			cin >> x >> y;
			a[i].x = x;
			a[i].y = y;
			a[i].p1 = x - sqrt((double)d * d - y * y);
			a[i].p2 = x + sqrt((double)d * d - y * y);
		}
		sort(a, a + n - 1, cmp);
		for (int i = 0; i < n; i++)
		{
			if (d<0 || a[i].y>d||n<0)
			{
				cout << "Case " << ++count << ":" <<-1<< endl;
				flag = 1;
				break;
			}
		}
		if (flag == 1)
		{
			flag = 0;
			continue;
		}
		double k = a[0].p2;
		ans = 1;
		for (int i = 1; i < n; i++)
		{
			if (a[i].p1 > k)
			{
				ans++;
				k = a[i].p2;
			}
			else if (a[i].p2 < k)
			{
				k = a[i].p2;
			}

		}
		cout << "Case " << ++count << ": " << ans << endl<<endl;
		ans = 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