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

  1. 4 1
  2. 0 1
  3. 0 2
  4. 0 3
  5. 0 4
  6. O 1
  7. O 2
  8. O 4
  9. S 1 4
  10. O 3
  11. S 1 4

Sample Output

  1. FAIL
  2. SUCCESS
  3.  
  4. //题意是,电脑都坏了,可以一个一个修复,电脑只能在一定的距离内才能连通,在询问是否连通的时候输出是否连通。
    第一行是 n d d 是代表电脑能连通的最大距离,然后是 n 行坐标,在然后是命令 O 代表修复电脑,S 代表查询两个电脑是否连通
  5.  
  6. 并查集简单的应用,压缩了路径就只用了1
    1125 ms
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. struct Com
  7. {
  8. int x,y;
  9. int on;
  10. }com[];
  11. int p[];
  12.  
  13. int find(int x)
  14. {
  15. if (x!=p[x])
  16. p[x]=find(p[x]);
  17. return p[x];
  18. }
  19.  
  20. int Distance(int a,int b,double x)
  21. {
  22. double j=(com[a].x-com[b].x)*(com[a].x-com[b].x);
  23. double k=(com[a].y-com[b].y)*(com[a].y-com[b].y);
  24. double l=sqrt(j+k);
  25. if (x<l)
  26. return ;
  27. return ;
  28. }
  29.  
  30. int main()
  31. {
  32. int n,i;
  33. double s;
  34. scanf("%d%lf",&n,&s);
  35. for (i=;i<=n;i++)
  36. {
  37. scanf("%d%d",&com[i].x,&com[i].y);
  38. com[i].on=;
  39. p[i]=i;
  40. }
  41. char str[];
  42. int k;
  43. while(scanf("%s",str)!=EOF)
  44. {
  45. if (str[]=='O')
  46. {
  47. scanf("%d",&k);
  48. if (com[k].on==)
  49. continue;
  50. com[k].on=;
  51. for (i=;i<=n;i++)
  52. {
  53. if (i==k||com[i].on==) //未修复
  54. continue;
  55. if (Distance(i,k,s))//距离超出
  56. continue;
  57. int fa=find(k);
  58. int fb=find(i);
  59. p[fa]=fb;
  60. }
  61. }
  62. if (str[]=='S')
  63. {
  64. int a,b;
  65. scanf("%d%d",&a,&b);
  66. int fa=find(a),fb=find(b);
  67. if (fa==fb)
  68. {
  69. printf("SUCCESS\n");
  70. //没有这种情况
  71. /* if (a!=b)
  72. printf("SUCCESS\n");
  73. else if (a==b&&com[a].on)
  74. printf("SUCCESS\n");
  75. else
  76. printf("FAIL\n");*/
  77. }
  78. else
  79. printf("FAIL\n");
  80. }
  81. }
  82. return ;
  83. }
  1.  
  1.  
  1.  

(比赛)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. 3. Spring Boot热部署【从零开始学Spring Boot】

    转载:http://blog.csdn.net/linxingliang/article/details/51584549 在编写代码的时候,你会发现我们只是简单把打印信息改变了下,就需要重新部署,如 ...

  2. 倍福TwinCAT(贝福Beckhoff)基础教程1.2 TwinCAT安装配置

    由于TC2和TC3都有可能用到,个人推荐都安装,但是注意必须是先安装的TwinCAT2,然后安装TwinCAT3,如果反了可能两个都没法用(打开TcSwitchRuntime提示Both TwinCA ...

  3. iOS11

    _tab.estimatedRowHeight = 0; if (@available(iOS 11.0, *)) { //当有heightForHeader delegate时设置 _tab.est ...

  4. Java 调用存储过程、函数

     一.Java调用存储Oracle存储过程 测试用表: --创建用户表 create table USERINFO ( username ) not null, password ) not null ...

  5. 标准库priority_queue的一种实现

    优先级队列相对于普通队列,提供了插队功能,每次最先出队的不是最先入队的元素,而是优先级最高的元素. 它的实现采用了标准库提供的heap算法.该系列算法一共提供了四个函数.使用方式如下: 首先,建立一个 ...

  6. 字典树-HDOJ-1247-Hat’s Words

    Hat's Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  7. 【经典数据结构】B树与B+树(转)

    本文转载自:http://www.cnblogs.com/yangecnu/p/Introduce-B-Tree-and-B-Plus-Tree.html 维基百科对B树的定义为“在计算机科学中,B树 ...

  8. C#中执行存储过程并在SQL server中调试

    1.编写存储过程 ) drop PROCEDURE [dbo].[sp_calcPci_of_baseRcd_GTmpTbl] CREATE PROCEDURE [dbo].[sp_calcPci_o ...

  9. 使用Gitolite搭建Gitserver

    Gitolite是一款Perl语言开发的Git服务管理工具.通过公钥对用户进行认证.并可以通过配置文件对些操作进行基于分支和路径的精细控制. Gitolite採用的是SSH协议而且使用SSH公钥认证. ...

  10. 【leetcode】118. Pascal&#39;s Triangle

    @requires_authorization @author johnsondu @create_time 2015.7.23 19:54 @url [Pascal's Triangle](http ...