A - Simple String Problem

Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu

Description

An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are repaired one by one, and the network gradually began to work again. Because of the hardware restricts, each computer can only directly communicate with the computers that are not farther than d meters from it. But every computer can be regarded as the intermediary of the communication between two other computers, that is to say computer A and computer B can communicate if computer A and computer B can communicate directly or there is a computer C that can communicate with both A and B.

In the process of repairing the network, workers can take two kinds of operations at every moment, repairing a computer, or testing if two computers can communicate. Your job is to answer all the testing operations.

Input

The first line contains two integers N and d (1 <= N <= 1001, 0 <= d <= 20000). Here N is the number of computers, which are numbered from 1 to N, and D is the maximum distance two computers can communicate directly. In the next N lines, each contains two integers xi, yi (0 <= xi, yi <= 10000), which is the coordinate of N computers. From the (N+1)-th line to the end of input, there are operations, which are carried out one by one. Each line contains an operation in one of following two formats: 
1. "O p" (1 <= p <= N), which means repairing computer p. 
2. "S p q" (1 <= p, q <= N), which means testing whether computer p and q can communicate.

The input will not exceed 300000 lines.

Output

For each Testing operation, print "SUCCESS" if the two computers can communicate, or "FAIL" if not.

Sample Input

4 1
0 1
0 2
0 3
0 4
O 1
O 2
O 4
S 1 4
O 3
S 1 4

Sample Output

FAIL
SUCCESS //题意是,电脑都坏了,可以一个一个修复,电脑只能在一定的距离内才能连通,在询问是否连通的时候输出是否连通。
第一行是 n ,d ,d 是代表电脑能连通的最大距离,然后是 n 行坐标,在然后是命令 O 代表修复电脑,S 代表查询两个电脑是否连通 并查集简单的应用,压缩了路径就只用了1秒
1125 ms
 #include <iostream>
#include <stdio.h>
#include <math.h>
using namespace std; struct Com
{
int x,y;
int on;
}com[];
int p[]; int find(int x)
{
if (x!=p[x])
p[x]=find(p[x]);
return p[x];
} int Distance(int a,int b,double x)
{
double j=(com[a].x-com[b].x)*(com[a].x-com[b].x);
double k=(com[a].y-com[b].y)*(com[a].y-com[b].y);
double l=sqrt(j+k);
if (x<l)
return ;
return ;
} int main()
{
int n,i;
double s;
scanf("%d%lf",&n,&s);
for (i=;i<=n;i++)
{
scanf("%d%d",&com[i].x,&com[i].y);
com[i].on=;
p[i]=i;
}
char str[];
int k;
while(scanf("%s",str)!=EOF)
{
if (str[]=='O')
{
scanf("%d",&k);
if (com[k].on==)
continue;
com[k].on=;
for (i=;i<=n;i++)
{
if (i==k||com[i].on==) //未修复
continue;
if (Distance(i,k,s))//距离超出
continue;
int fa=find(k);
int fb=find(i);
p[fa]=fb;
}
}
if (str[]=='S')
{
int a,b;
scanf("%d%d",&a,&b);
int fa=find(a),fb=find(b);
if (fa==fb)
{
printf("SUCCESS\n");
//没有这种情况
/* if (a!=b)
printf("SUCCESS\n");
else if (a==b&&com[a].on)
printf("SUCCESS\n");
else
printf("FAIL\n");*/
}
else
printf("FAIL\n");
}
}
return ;
}

 
 

(比赛)A - Simple String Problem的更多相关文章

  1. FZU - 2218 Simple String Problem(状压dp)

    Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...

  2. FZU - 2218 Simple String Problem 状压dp

    FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...

  3. fzu2218 Simple String Problem

    Accept: 2    Submit: 16 Time Limit: 2000 mSec    Memory Limit : 32768 KB  Problem Description Recent ...

  4. FZU 2218 Simple String Problem(简单字符串问题)

    Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...

  5. FZU2218 Simple String Problem(状压DP)

    首先,定义S,表示前k个字符出现的集合,用二进制来压缩. 接下来,推出dp1[S],表示集合为S的子串的最长长度. 然后根据dp1[S]再推出dp2[S],表示集合为S或S的子集的子串的最长长度. 最 ...

  6. FZU-2218 Simple String Problem(状态压缩DP)

      原题地址: 题意: 给你一个串和两个整数n和k,n表示串的长度,k表示串只有前k个小写字母,问你两个不含相同元素的连续子串的长度的最大乘积. 思路: 状态压缩DP最多16位,第i位的状态表示第i位 ...

  7. Water --- CSU 1550: Simple String

    Simple String Problem's Link:   http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...

  8. hdu4976 A simple greedy problem. (贪心+DP)

    http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...

  9. hdu 1757 A Simple Math Problem (乘法矩阵)

    A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Ot ...

随机推荐

  1. 计算GPS两点间的距离[单位为:米]

    /**     * 计算GPS两点间的距离[单位为:米]     * @param center GPS当前数据(LonLat对象表示,LonLat.lon表示经度,LonLat.lat表示纬度)   ...

  2. Nginx常用Rewrite(伪静态规则)WordPress/PHPCMS/ECSHOP/ShopEX/SaBlog/Discuz/DiscuzX/PHPWind/Typecho/DEDECMS

    目前已收集Wordpress.Wordpress二级目录.PHPCMS.ECSHOP.ShopEX.SaBlog.Discuz.Discuz X.PHPWind.Typecho.DEDECMS: Wo ...

  3. JAVA Eclipse如何开发Android的多页面程序

    Fragment可以认为是Activity的一个界面的组成部分,Fragment必须依存于Activity.   在layout文件夹中新建一个xml文件,布局方式采用RelativeLayout,注 ...

  4. 福利来了,全国路网数据,poi数据

    本人现有全国路网数据,POI数据,均为原始数据.无偏移,都已分类,如图所示.有意请联系(QQ204843224), 兴趣点包含: 餐饮.村庄.大厦.服务区.公安交警.购物.火车站.机场.加油站.交通. ...

  5. 怎么运行Typescript

    依据官方示例: npm i -g typescript 示例:tsc *.ts 实例:tsc hello.ts 不过以上实现的太有限制了,如下实现可满足正常测试以及学习使用 package,json ...

  6. #include <>与#include""区别

    <>先去系统目录中找头文件,如果没有在到当前目录下找.所以像标准的头文件 stdio.h.stdlib.h等用这个方法. 而""首先在当前目录下寻找,如果找不到,再到系 ...

  7. 在HTML页面中实现一个简单的Tab

    参考:http://blog.sina.com.cn/s/blog_6cccb1630100m23i.html HTML页面代码如下: <!DOCTYPE html PUBLIC "- ...

  8. 【Spring】使用Filter过滤请求

    原文:http://liujiajia.me/#/blog/details/spring-filter-request-with-filter public class CustomizedFilte ...

  9. 【BIEE】11_BIEE图形报表在谷歌浏览器64.0.3282.140中访问图例乱码解决

    如上图,使用谷歌浏览器访问BIEE图形报表的时候,标题.图例等涉及到中文的地方全部乱码了!但是用IE打开是不会乱码的,这是由于:谷歌需要设置编码格式 但是55版本以后,谷歌公司为了加快浏览器的速度,提 ...

  10. 后期给项目加入Git版本控制

    一.为项目加上Git 1.进入对应文件夹 2.git init(初始化一个空的代码仓库) 3.git add .(将当前目录和子目录的文件标记为要添加到代码仓库) 4.git commit -m &q ...