(比赛)A - Simple String Problem
A - Simple String Problem
Time Limit:10000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
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
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
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的更多相关文章
- FZU - 2218 Simple String Problem(状压dp)
Simple String Problem Recently, you have found your interest in string theory. Here is an interestin ...
- FZU - 2218 Simple String Problem 状压dp
FZU - 2218Simple String Problem 题目大意:给一个长度为n含有k个不同字母的串,从中挑选出两个连续的子串,要求两个子串中含有不同的字符,问这样的两个子串长度乘积最大是多少 ...
- fzu2218 Simple String Problem
Accept: 2 Submit: 16 Time Limit: 2000 mSec Memory Limit : 32768 KB Problem Description Recent ...
- FZU 2218 Simple String Problem(简单字符串问题)
Description 题目描述 Recently, you have found your interest in string theory. Here is an interesting que ...
- FZU2218 Simple String Problem(状压DP)
首先,定义S,表示前k个字符出现的集合,用二进制来压缩. 接下来,推出dp1[S],表示集合为S的子串的最长长度. 然后根据dp1[S]再推出dp2[S],表示集合为S或S的子集的子串的最长长度. 最 ...
- FZU-2218 Simple String Problem(状态压缩DP)
原题地址: 题意: 给你一个串和两个整数n和k,n表示串的长度,k表示串只有前k个小写字母,问你两个不含相同元素的连续子串的长度的最大乘积. 思路: 状态压缩DP最多16位,第i位的状态表示第i位 ...
- Water --- CSU 1550: Simple String
Simple String Problem's Link: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1550 Mean: 略. analy ...
- hdu4976 A simple greedy problem. (贪心+DP)
http://acm.hdu.edu.cn/showproblem.php?pid=4976 2014 Multi-University Training Contest 10 1006 A simp ...
- hdu 1757 A Simple Math Problem (乘法矩阵)
A Simple Math Problem Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Ot ...
随机推荐
- OpenGL变换【转】
http://www.cnblogs.com/hefee/p/3811099.html OpenGL变换 概述 OpenGL变换矩阵 实例:GL_MODELVIEW矩阵 实例:GL_PROJECTIO ...
- 让Mac支持lrzsz
http://blog.csdn.net/citywolf4/article/details/49071679 https://github.com/mmastrac/iterm2-zmodem
- 转: 阿里跨平台移动开发工具Weex
对于移动开发者来说,Weex主要解决了频繁发版和多端研发两大痛点,同时解决了前端语言性能差和显示效果受限的问题.开发者可通过Weex官网申请内测.(http://alibaba.github.io/w ...
- 64位windows2003 未在本地计算机上注册 microsoft.jet.oledb.4.0 提供程序
64位windows2003系统 使用 mdb数据库时候出现如下错误. 可能用office的一些比较旧的程序时候会这样. 未在本地计算机上注册 microsoft.jet.oledb.4.0 提供程序 ...
- Window 7 开 WIFI做热点
cmd下两个命令即可: C:\Users\lyx>netsh wlan set hostednetwork mode=allow ssid=ACE-PC key=12345678承载网络模式已设 ...
- git个人使用总结(命令版)
一.基础命令 快照类操作:add.status.diff.commit.reset.rm.mv 分支类基本操作:branch.checkout.log.stash 分享及更新项目基本操作:pull.p ...
- java中按字节获得字符串长度的两种方法 Java问题通用解决代码
jdk本身就自带获取字符串字节长度的api了,但字符串如果包含特殊符号或全半角符号或标点符号获取到的结果会有偏差,最好的证据就是新浪微博的字数统计了 // jdk自带的获取字节长度 //注意getBy ...
- MongoDB基本命令使用
成功启动MongoDB后,再打开一个命令行窗口输入mongo,就可以进行数据库的一些操作. 输入help可以看到基本操作命令: show dbs:显示数据库列表 show collections:显示 ...
- Eclipse个最实用的快捷键
一个Eclipse骨灰级开发人员总结了他觉得最实用但又不太为人所知的快捷键组合.通过这些组合能够更加easy的浏览源码,使得总体的开发效率和质量得到提升. 1. ctrl+shift+r:打开 ...
- 修改eclipse的repository路径
(1)首先修改你的settings.xml文件,(如果没有settings.xml文件,可以下载maven的官网把maven的插件下载下来,在apache-maven-3.5.0\conf\ 目录下有 ...