poj 1328
来源:互联网 发布:putty串口发送数据 编辑:程序博客网 时间:2024/06/12 20:37
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
struct dot
{
int x;
int y;
}abc[10000];
struct rad
{
float left;
float right;
}rads[10000];
int comp(const void* a, const void* b)
{
int aa = (*(rad*)a).right;
int bb = (*(rad*)b).right;
return aa - bb;
}
int main()
{
int num, r;
cin >> num >> r;
bool flag = false;
int count = 0;
int ans[1000];
memset(ans, 0, sizeof(ans));
while (num != 0 || r != 0)
{
flag = false;
count++;
int cir = 0;
for (int i = 0; i < num; i++)
{
dot temp;
cin >> temp.x >> temp.y;
if (temp.y > r||temp.y<0)
flag = true;
abc[i] = temp;
}
if (flag)
{
ans[count] = -1;
}
else
{
for(int i=0;i<num;i++)
{
rads[i].left = abc[i].x - sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
rads[i].right = abc[i].x + sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
}
qsort(rads, num, sizeof(rads[0]), comp);
rad temp = rads[0];
cir++;
float now = rads[0].right;
for (int i = 1; i < num; i++)
{
temp = rads[i];
if (now >= temp.left)
{
continue;
}
else
{
now = temp.right;
cir++;
}
}
ans[count] = cir;
}
cin >> num >> r;
}
for(int i=1;i<=count;i++)
{
cout << "Case " << i << ": " << ans[i] << endl;
}
return 0;
}
#include<queue>
#include<math.h>
#include<algorithm>
using namespace std;
struct dot
{
int x;
int y;
}abc[10000];
struct rad
{
float left;
float right;
}rads[10000];
int comp(const void* a, const void* b)
{
int aa = (*(rad*)a).right;
int bb = (*(rad*)b).right;
return aa - bb;
}
int main()
{
int num, r;
cin >> num >> r;
bool flag = false;
int count = 0;
int ans[1000];
memset(ans, 0, sizeof(ans));
while (num != 0 || r != 0)
{
flag = false;
count++;
int cir = 0;
for (int i = 0; i < num; i++)
{
dot temp;
cin >> temp.x >> temp.y;
if (temp.y > r||temp.y<0)
flag = true;
abc[i] = temp;
}
if (flag)
{
ans[count] = -1;
}
else
{
for(int i=0;i<num;i++)
{
rads[i].left = abc[i].x - sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
rads[i].right = abc[i].x + sqrt(r*r*1.0 - abc[i].y*abc[i].y*1.0);
}
qsort(rads, num, sizeof(rads[0]), comp);
rad temp = rads[0];
cir++;
float now = rads[0].right;
for (int i = 1; i < num; i++)
{
temp = rads[i];
if (now >= temp.left)
{
continue;
}
else
{
now = temp.right;
cir++;
}
}
ans[count] = cir;
}
cin >> num >> r;
}
for(int i=1;i<=count;i++)
{
cout << "Case " << i << ": " << ans[i] << endl;
}
return 0;
}
阅读全文
1 0
- poj 1083 & poj 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ--1328
- poj-1328
- POJ 1328
- POJ 1328
- poj 1328
- poj 1328
- POJ 1328
- POJ 1328
- POJ 1328
- poj 1328
- SAS Enterprise Miner 学习笔记
- Python的socket
- 滑动条(Slider)插件
- 设计模式——行为扩展
- 最近用小程序遇到的坑
- poj 1328
- 设计模式——算法封装
- wordpress评论审核通过发邮件给评论者
- 存储器层次结构(一)
- curl和php Curl
- Day 6 linux基础命令练习三
- Cocos2dx lua 程序入口
- 手动升级openvswitch版本以替换mininet自带的openvswitch
- LeetCode 435. Non-overlapping Intervals