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. paho-mqtt

    mqtt 参考: https://pypi.org/project/paho-mqtt/ https://github.com/eclipse/paho.mqtt.python #服务端 [root@ ...

  2. linux fork的缺点

    Disadvantage of fork linux环境下, JBoss中调用curl下载文件,  发现curl占用的内存和JBoss一样多. Historical Background and Pr ...

  3. ASP.NET MVC学习---(五)MVC初体验

    经过之前n多的铺垫 我们已经大概了解了这个姓m名vc的家伙了 那么今天我们就来体验一把 怎么体验呢? 就来做一个小例子吧~ mvc增删改查的例子 数据库还是之前我们的老朋友 关系图: 表中的数据已填好 ...

  4. 转: java语法与ide级入门介绍 from: IBM dev

    点评: 讲的比较初级,但是有教你使用ide (Eclipse) frrom:http://www.ibm.com/developerworks/java/tutorials/j-introtojava ...

  5. 倍福TwinCAT(贝福Beckhoff)基础教程 松下伺服驱动器报错 81.0怎么办

    同步周期有问题   请确认MOTION的伺服周期是一致的,最好跟MAIN主程序也一样,所有周期都是2ms即可     更多教学视频和资料下载,欢迎关注以下信息: 我的优酷空间: http://i.yo ...

  6. Laravel之目录结构

    一.根目录 新安装的 Laravel 应用包含许多文件夹:• app 目录包含了应用的核心代码:• bootstrap 目录包含了少许文件用于框架的启动和自动载入配置,还有一个cache 文件夹用于包 ...

  7. URAL 1984. Dummy Guy(数学啊)

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1984 1984. Dummy Guy Time limit: 0.5 second Me ...

  8. 【Mysql】 你会用 information_schema吗?

    示例 select * from information_schema.views 其中的views可以替换成以下的字段,以下未列举的一般的数据库操作工具,在information_schema后输入 ...

  9. SQLserver备份数据库示例

     BACKUP DATABASE [yee]TO  DISK = N'D:\数据库备份\yee2015.9.11.bak'WITH  NAME = N'yee - 备份',  NOFORMAT, NO ...

  10. 3D版翻页公告效果

    代码地址如下:http://www.demodashi.com/demo/12830.html 前言: 在逛小程序蘑菇街的时候,看到一个2D版滚动的翻页公告效果.其实看到这个效果的时候,一点都不觉得稀 ...