CSU 1857 Crash and Go(relians)(模拟)
Crash and Go(relians)
【题目链接】Crash and Go(relians)
【题目类型】模拟
&题解:
这就是要严格的按照题意说的模拟就好了,也就是:每次添加进来一个圆,就找以前的,看有没有可以合成的多个圆,有的话就合成一起,这块要注意,合成之后,你一定要再从头跑一遍,因为合成之后的圆,有可能和之前联系不上的圆联系上了,所以这块就要多跑一个循环
【时间复杂度】\(O(n^2)\)
&代码:
#include <cstdio>
#include <iostream>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define INF 0x3f3f3f3f
using ll=long long;
const int maxn= 1e2 +9;
int n;
struct po
{
double x,y,r;
}te;
vector<po> vp;
double dis(po u,po v)
{
return sqrt((u.x-v.x)*(u.x-v.x)+(u.y-v.y)*(u.y-v.y));
}
bool ok(po u,po v)
{
return dis(u,v)<max(u.r,v.r);
}
void sol(int pos,vector<po>& tt)
{
double x=0,y=0,r=0;
for(int i=0;i<tt.size();i++){
x+=tt[i].x;
y+=tt[i].y;
r+=tt[i].r*tt[i].r;
}
vp[pos].x=x/tt.size();
vp[pos].y=y/tt.size();
vp[pos].r=sqrt(r);
}
int main()
{
// ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
freopen("E:1.txt","r",stdin);
while(cin>>n){
if(n==0) break;
vp.clear();
for(int i=0;i<n;i++){
double u,v,r;
cin>>u>>v>>r;
vp.push_back(po{u,v,r});
}
for(int i=0;i<n;i++) {
vector<po> feasible;
feasible.push_back(vp[i]);
for(int j=0;j<i;j++) if(vp[j].r>0)
{
// if(i==4) printf("%d ---\n",j);
if(ok(vp[i],vp[j])){
// printf("======= i=%d j=%d\n",i,j);
feasible.push_back(vp[j]);
vp[j].r=-1;
}
}
if(feasible.size()>1){
sol(i,feasible);
//这块就是新合成的一个圆 所以你要把它再循环一遍看之前有没有可以联系上的其他人
i--;
}
}
int ans=0;
for(int i=0;i<n;i++){
// printf("vp[%d] x=%f y=%f r=%f\n",i,vp[i].x,vp[i].y,vp[i].r);
if(vp[i].r>0) ans++;
}
cout<<ans<<endl;
}
return 0;
}
CSU 1857 Crash and Go(relians)(模拟)的更多相关文章
- 模拟 CSU 1562 Fun House
题目传送门 /* 题意:光线从 '*' 发射,遇到 '/' 或 '\' 进行反射,最后射到墙上,将 'x' 变成 '&' 模拟:仔细读题,搞清楚要做什么,就是i,j的移动,直到撞到墙,模拟一下 ...
- csu 1312 榜单(模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1312 1312: 榜单 Time Limit: 1 Sec Memory Limit: 128 ...
- 【模拟】CSU 1807 最长上升子序列~ (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1807 题目大意: 给你一个长度为N(N<=105)的数列,数列中的0可以被其他数 ...
- 【模拟】【数学】CSU 1803 2016 (2016湖南省第十二届大学生计算机程序设计竞赛)
题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1803 题目大意: 给定n,m(n,m<=109)1<=i<=n,1& ...
- csu - 1536: Bit String Reordering (模拟)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1536 不知道为何怎么写都写不对. 这题可以模拟. 虽然题目保证一定可以从原串变成目标串,但是不一定 ...
- CSU 1862 The Same Game(模拟)
The Same Game [题目链接]The Same Game [题目类型]模拟 &题解: 写这种模拟题要看心态啊,还要有足够的时间,必须仔细读题,一定要写一步,就调试一步. 这题我没想到 ...
- csu 1549: Navigition Problem(几何,模拟)
1549: Navigition Problem Time Limit: 1 Sec Memory Limit: 256 MBSubmit: 305 Solved: 90[Submit][Stat ...
- CSU 1023 修路(二分+模拟)
前段时间,某省发生干旱,B山区的居民缺乏生活用水,现在需要从A城市修一条通往B山区的路.假设有A城市通往B山区的路由m条连续的路段组成,现在将这m条路段承包给n个工程队(n ≤ m ≤ 300).为了 ...
- csu - 1537: Miscalculation (模拟题)
http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1537 因为给出的式子是必定合法的,只要用两个栈分别保存符号和数字.算出答案后和从左至右算的答案比对 ...
随机推荐
- struts2 中 paramsPrepareParamsStack 拦截器
struts2二次参数拦截器内容: 规定了请求的执行顺序 在struts2中,其拦截器为框架精华部分,而二次参数拦截器paramsPrepareParamsStack 对于解决数据回显,对象修改属性 ...
- Instruments之Activity Monitor使用入门
Activity Monitor,官方解释为:(活动监视器)即实时显示CPU.内存和网络的使用情况,记录由虚拟内存大小测量的系统负载.用一句大白话来说,Activity Monitor类似Window ...
- 在dbgrideh中允许选择多行,如何知道哪些行被选中
是个BOOKMARK类型的属性. SelectedRows: TBookmarkList procedure TForm1.Button1Click(Sender: TObject); var i, ...
- dbtool部署
dbtool工具部署 a.附件解压到/home/oracle/dbtool b.执行以下命令chmod 755 /home/oracle/dbtool/*.shecho "alias dbt ...
- glove理解
先贴个看起来讲的不错的文章链接,后续详细看了再补充https://blog.csdn.net/leyounger/article/details/78206832 2018.10.28大概了解了下gl ...
- kvc原理
KVC底层实现原理 第一步:寻找该属性有没有setsetter方法?有,就直接赋值 第二步:寻找有没有该属性带下划线的成员属性?有,就直接赋值 第三步:寻找有没有该属性的成员属性?有,就直接赋值 1. ...
- Java高频面试题
网络相关 1.http1.0和http1.1的区别? http1.0每次请求都需要和服务器建立一个TCP连接,服务器完成请求后立即断开TCP连接. http1.1支持长连接,客户端在http请求头上加 ...
- web应用1
阅读内容 一.web应用 二.web协议 三.web框架 四.补充知识 回到顶部 一.web应用 二.web协议 三.web框架 四.补充知识 五.补充知识
- Redis入门到高可用(二)—— Redis启动及使用
1. 三种启动方式 ♦️ 最简启动 ./redis-server 使用Redis默认配置进行启动; ♦️ 动态参数启动 * redis-server --port 6380 更改端口为6380并 ...
- 多线程——newFixedThreadPool线程池
newFixedThreadPool线程池: 理解: 1.固定线程数的线程池. 2.通过Executors中的静态方法创建: public static ExecutorService new ...