poj 2236:Wireless Network(并查集,提高题)

Wireless Network
Time Limit: 10000MS Memory Limit: 65536K
Total Submissions: 16065 Accepted: 6778

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

Source

 
  并查集,提高题
  算是并查集的应用,拐了点弯。
 
  题意
  有一个计算机网络的所有线路都坏了,网络中有n台计算机,现在你可以做两种操作,修理(O)和检测两台计算机是否连通(S),只有修理好的计算机才能连通。连通有个规则,两台计算机的距离不能超过给定的最大距离D(一开始会给你n台计算机的坐标)。检测的时候输出两台计算机是否能连通。
 
  思路
  每次修理好一台计算机的时候就遍历一下所有修好的计算机,看距离是否<=D,如果符合说明可以连通,将两台计算机所在集合合并。
  每次检查的时候判断一下这两台计算机是否在同一集合中即可。
 
  注意
  1、坐标之后给出的计算机编号都是n+1的。例如O 3,他实际上修理的是编号为2的计算机,因为计算机是从0开始编号的。
  2、比较距离的时候注意要用浮点数比较,否则会WA。
  3、"FAIL"不要写成"FALL"。
  4、字符串输入的时候注意处理好回车,空格等情况。
  5、注意N的范围(1 <= N <= 1001),最大是1001,不是1000。是个小坑,数组开小了可能会错哦。
 
  另外测试了一下使用路径压缩,和不使用路径压缩的效率。使用是1079MS(C++),不使用是2032MS(C++),时间缩短了一倍。
  另外C++和G++提交时间相差也很大。同样的代码G++就变成了3063MS(G++)。
 
  代码
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <cmath>
 4 using namespace std;
 5 
 6 #define MAXN 1010
 7 
 8 int dx[MAXN],dy[MAXN];    //坐标
 9 int par[MAXN];    //par[x]表示x的父节点
10 int repair[MAXN] ={0};
11 int n;
12 
13 void Init()    //初始化
14 {
15     int i;
16     for(i=0;i<=n;i++)
17         par[i] = i;
18 }
19 
20 int Find(int x)    //查询x的根节点并路径压缩
21 {
22     if(par[x]!=x)
23         par[x] = Find(par[x]);
24     return par[x];
25 }
26 
27 void Union(int x,int y)    //合并x和y所在集合
28 {
29     par[Find(x)] = Find(y);
30 }
31 
32 int Abs(int n)
33 {
34     return n>0?n:-n;
35 }
36 
37 double Dis(int a,int b)
38 {
39     return sqrt( double(dx[a]-dx[b])*(dx[a]-dx[b]) + (dy[a]-dy[b])*(dy[a]-dy[b]) );
40 }
41 
42 int main()
43 {
44     int d,i;
45 
46     //初始化
47     scanf("%d%d",&n,&d);
48     Init();
49 
50     //输入坐标
51     for(i=0;i<n;i++){
52         scanf("%d%d",&dx[i],&dy[i]);
53     }
54     
55     //操作
56     char cmd[2];
57     int p,q,len=0;
58     while(scanf("%s",cmd)!=EOF){
59         switch(cmd[0]){
60         case 'O':
61             scanf("%d",&p);
62             p--;
63             repair[len++] = p;
64             for(i=0;i<len-1;i++)    //遍历所有修过的计算机,看能否联通
65                 if( repair[i]!=p && Dis(repair[i],p)<=double(d) )
66                     Union(repair[i],p);
67             break;
68         case 'S':
69             scanf("%d%d",&p,&q);
70             p--,q--;
71             if(Find(p)==Find(q))    //是否有路
72                 printf("SUCCESS\n");
73             else 
74                 printf("FAIL\n");
75         default:
76             break;
77         }
78     }
79 
80     return 0;
81 }

 

Freecode : www.cnblogs.com/yym2013

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Designing a Wireless network<br><br>Foreword xxv<br><br>From Past to Present 1<br><br>Introduction 2<br><br>Exploring Past Discoveries That Led to Wireless 4<br>Discovering Electromagnetism 4<br><br>Exploring Conduction 6<br><br>Inventing the Radio 6<br><br>Mounting Radio-Telephones in Cars 8<br><br>Inventing Computers and Networks 9<br><br>Inventing Cell Phones 11<br><br>Exploring Present Applications for Wireless 12<br>Vertical Markets 13<br>Using Wireless in Delivery Services 14<br>Using Wireless for Public Safety 14<br>Using Wireless in the Financial World 15<br>Using Wireless in the Retail World 15<br>Using Wireless in Monitoring<br>Applications 16<br>Applying Wireless Technology to Horizontal<br>Applications 16<br>Using Wireless in Messaging 17<br>Using Wireless for Mapping 17<br>Using Wireless for Web Surfing 17<br>Exploring This Book on Wireless 18<br>xiii<br><br>Summary 19<br>Solutions Fast Track 20<br>Frequently Asked Questions 21<br>Chapter 2 Radio Elements and Frequency Spectrums 23<br>Introduction 24<br>Learn the Properties of Transmitting Radio Signals Over EM Waves 24<br>Waveforms<br>Anatomy of a Waveform 25<br>Modulating a Radio Signal 27<br>a = Amplitude<br>Propagating a Strong Radio Signal 34<br>v = Velocity of Propagation<br>Understanding Signal Power and<br>τ = Period<br>Signal-to-Noise Ratio 35<br>λ = Wavelength<br>Attenuation 36<br>? = Frequency<br>Rain Attenuation 39<br>Bouncing 39<br>Refracting 41<br>Line of Sight 42<br>Penetration 43<br>Understanding the Wireless Elements 45<br>Generic Radio Components 45<br>Antennas 49<br>Omnidirectional Antennas 50<br>Directional Antennas 51<br>Base Stations and Mobile Stations 56<br>Access Points 57<br>Channelizing the Frequency Spectrum 57<br>Channelizing 59<br>Channel Bandwidth 59<br>Channel Spacing and Buffer Zones 60<br>Multichannel Systems and Channel<br>Offsets 61<br>Extending the Number of Channels<br>(Frequency Reuse) 61<br>Seven Cell Frequency Reuse 62<br>Multiple Accessing 63<br><br>152_wan_toc 6/22/01 4:54 PM Page xv<br>Contents xv<br>Regulating Wireless Communications 64<br>Regulatory Agencies 64<br>The Need to Know 65<br>Regulations for Low Power,Unlicensed<br>Transmitters 66<br>Summary 68<br>Solutions Fast Track 69<br>Frequently Asked Questions 71<br>Chapter 3 TCP/IP and the OSI Model 73<br>Learn to Configure<br>Introduction 74<br>and Maintain Routes<br>Exploring the OSI and DoD Models 74<br>for Full Connectivity<br>Layer 1:The Physical Layer 75<br>Layer 2:The Data-Link Layer 75<br>PC<br>Layer 3:The Network Layer 77<br>Layer 4:The Transport Layer 78<br>T3<br>A<br>T1<br>Layer 5:The Session Layer 78<br>F<br>T3<br>E<br>B<br>Layer 6:The Presentation Layer 79<br>D<br>T3<br>Layer 7:The Application Layer 80<br>T1<br>C<br>T3<br>OSI and DoD Correlation 81<br>Understanding the Network Access Layer 81<br>Server<br>Using Bridging 82<br>The Ethernet Protocol 85<br>Static Routing in a<br>Understanding the ARP Process 86<br>Multihop, Multipath<br>Network<br>Wireless Protocols 87<br>Other Network Access Protocols 88<br>Understanding the Internet Layer 88<br>The Internet Protocol 89<br>IP Addressing 91<br>Conserving Address Space with VLSM 93<br>Routing 95<br>The Internet Control Message Protocol 101<br>Understanding the Host-to-Host Layer 101<br>User Datagram Protocol 102<br>Transmission Control Protocol 102<br>Managing the Application Layer 105<br>Monitoring Tools:SNMP 105<br><br>152_wan_toc 6/22/01 4:54 PM Page xvi<br>xvi Contents<br>Assigning Addresses with DHCP 105<br>Conserving with Network Address<br>Translation 106<br>Summary 110<br>Solution Fast Track 111<br>Frequently Asked Questions 113<br>Chapter 4 Identifying Evolving Wireless<br>Technologies and Standards 115<br>Understand Bluetooth<br>Introduction 116<br>Piconet and Scatternet<br>Fixed Wireless Technologies 117<br>Configuration<br>Multichannel Multipoint Distribution Service 117<br>Local Multipoint Distribution Services 119<br>Scatternet<br>Wireless Local Loop 120<br>Piconet 1 Piconet 2<br>Point-to-Point Microwave 121<br>Legend<br>P S<br>SB<br>SB<br>Wireless Local Area Networks 122<br>Master<br>M<br>S<br>Slave<br>10 m<br>S M<br>M S<br>Why the Need for a Wireless LAN Standard? 123<br>P<br>Parked<br>S S<br>Standby<br>SB<br>What Exactly Does the 802.11 Standard<br>S P<br>Define? 125<br>Does the 802.11 Standard Guarantee <br>Compatibility across Different Vendors? 128<br>802.11b 130<br>802.11a 131<br>802.11e 132<br>Developing WLANs through the 802.11<br>Architecture 133<br>The Basic Service Set 133<br>The Extended Service Set 135<br>Services to the 802.11 Architecture 135<br>The CSMA-CA Mechanism 138<br>The RTS/CTS Mechanism 138<br>Acknowledging the Data 139<br>Configuring Fragmentation 140<br>Using Power Management Options 140<br>Multicell Roaming 140<br>Security in the WLAN 141<br><br>152_wan_toc 6/22/01 4:54 PM Page xvii<br>Contents xvii<br>Developing WPANs through the 802.15<br>Architecture 143<br>Bluetooth 144<br>HomeRF 147<br>High Performance Radio LAN 147<br>Mobile Wireless Technologies 148<br>First Generation Technologies 150<br>Second Generation Technologies 150<br>2.5G Technology 150<br>Third Generation Technologies 151<br>Wireless Application Protocol 151<br>Global System for Mobile Communications 153<br>General Packet Radio Service 155<br>Short Message Service 155<br>Optical Wireless Technologies 156<br>Summary 157<br>Solutions Fast Track 159<br>Frequently Asked Questions 163<br>Chapter 5 Designing a Wireless Network 165<br>Introduction 166<br>Create a Detailed<br>Exploring the Design Process 166<br>Physical Design<br>Conducting the Preliminary Investigation 167<br>Performing Analysis of the Existing<br>Equipment model<br>Environment 168<br>Cabling details<br>Creating a Preliminary Design 169<br>Rack details<br>Finalizing the Detailed Design 169<br>Environment<br>Executing the Implementation 170<br>requirements<br>Capturing the Documentation 171<br>Physical location of<br>Identifying the Design Methodology 172<br>devices<br>Creating the Network Plan 173<br>Detailed RF design<br>Gathering the Requirements 173<br>Baselining the Existing Network 175<br>Analyzing the Competitive Practices 176<br>Beginning the Operations Planning 176<br>Performing a Gap Analysis 176<br>Creating a Technology Plan 177<br><br>152_wan_toc 6/22/01 4:54 PM Page xviii<br>xviii Contents<br>Creating an Integration Plan 178<br>Beginning the Collocation Planning 178<br>Performing a Risk Analysis 179<br>Creating an Action Plan 179<br>Preparing the Planning Deliverables 180<br>Developing the Network Architecture 180<br>Reviewing and Validating the Planning<br>Phase 181<br>Creating a High-Level Topology 181<br>Creating a Collocation Architecture 182<br>Defining the High-Level Services 182<br>Creating a High-Level Physical Design 183<br>Defining the Operations Services 183<br>Creating a High-Level Operating Model 184<br>Evaluating the Products 184<br>Creating an Action Plan 185<br>Creating the Network Architecture<br>Deliverable 186<br>Formalizing the Detailed Design Phase 186<br>Reviewing and Validating the Network<br>Architecture 186<br>Creating the Detailed Topology 187<br>Creating a Detailed Service Collocation<br>Design 188<br>Creating the Detailed Services 188<br>Creating a Detailed Physical Design 189<br>Creating a Detailed Operations Design 190<br>Creating a Detailed Operating Model<br>Design 190<br>Creating a Training Plan 191<br>Developing a Maintenance Plan 192<br>Developing an Implementation Plan 192<br>Creating the Detailed Design Documents 192<br>Understanding Wireless Network Attributes<br>from a Design Perspective 193<br>Application Support 194<br>Subscriber Relationships 196<br><br>152_wan_toc 6/22/01 4:54 PM Page xix<br>Contents xix<br>Physical Landscape 197<br>Network Topology 200<br>Network Security 201<br>Summary 203<br>Solutions Fast Track 204<br>Frequently Asked Questions 206<br>Chapter 6 Designing a Wireless Enterprise<br>Use Two Wireless<br>Network: Hospital Case Study 209<br>Outdoor Routers to<br>Introduction 210<br>Create Redundancy<br>Applying Wireless in an Enterprise Network 210<br>Introducing the Enterprise Case Study 211<br>To Building 100 To Main Hospital11 Mbps link<br>Building 100 Router<br>Assessing the Opportunity 211<br>To Building 101<br>To Building 101<br>Evaluating Network Requirements 213<br>To Building 200<br>Main Hospital Router<br>Assessing the Satellite Buildings’Physical<br>To Building 201<br>Landscape 214<br>To Building 300<br>Evaluating the Outside Physical Landscape 214<br>To Building 301<br>Evaluating the Current Network 216<br>Evaluating the Hospital Conference Room<br>Networking Landscape 216<br>Designing a Wireless Solution 217<br>Project 1:Providing Satellite Building Access 218<br>Project 2:Providing Wireless Technology<br>to the Conference Rooms 219<br>Project 3:Providing Building-to-Building<br>Connectivity 220<br>Describing the Detailed Design of the<br>Building Links 222<br>Implementing and Testing the Wireless Solution 224<br>Project 1:Implementing the Satellite<br>Building LAN Access 224<br>Project 2:Implementing the Hospital<br>Conference Room 224<br>Project 3:Implementing the<br>Building-to-Building Connectivity 225<br>Reviewing the Hospital’s Objectives 227<br>Lessons Learned 228<br><br>152_wan_toc 6/22/01 4:54 PM Page xx<br>xx Contents<br>Summary 229<br>Solutions Fast Track 230<br>Frequently Asked Questions 232<br>Chapter 7 Designing a Wireless Industrial<br>Network: Retail Case Study 233<br>Create an Installation<br>Introduction 234<br>Checklist and Verify<br>the Steps on the List<br>Applying Wireless Technology in an Industrial<br>Network 235<br>Set up the IP<br>Introducing the Industrial Case Study 235<br>information<br>Assessing the Opportunity 236<br>Install the access points<br>Defining the Scope of the Case Study 238<br>Install the AP Manager<br>Reviewing the Current Situation 238<br>software<br>Designing and Implementing the Wireless<br>Test the wireless<br>Network 239<br>network<br>Creating the High-Level Design 239<br>Review the client’s<br>Creating a Detailed Design 240<br>objectives<br>Obtaining a Physical Map 242<br>Determining User Density 247<br>Identifying Constraints 248<br>Conducting the Walk-Through 249<br>Identifying RF Interface Sources 249<br>Plan the RF Pattern for the Network 249<br>Planning the Equipment Placement 250<br>Determining Where to Place the Access<br>Points 251<br>Determining the RF Channel<br>Optimization 254<br>Identifying IP Addresses 255<br>Implementing the Wireless Network 255<br>Selecting the Hardware 256<br>Installing the Wireless Components 258<br>Setting Up IP Information 258<br>Installing the Access Points 258<br>Install the AP Manager Software 260<br>Installing the PC Card in Shipping/<br>Receiving 260<br><br>152_wan_toc 6/22/01 4:54 PM Page xxi<br>Contents xxi<br>Testing the Wireless Network 260<br>Reviewing the Client’s Objectives 261<br>Lessons Learned 262<br>Summary 263<br>Solutions Fast Track 264<br>Frequently Asked Questions 266<br>Chapter 8 Designing a Wireless Campus<br>Network: University Case Study 269<br>Introduction 270<br>Applying Wireless Technology in a Campus<br>Network 270<br>Introducing the Campus Case Study 271<br>Establish High-Level<br>Assessing the Opportunity 271<br>Inter-Building<br>Defining the Scope of the Case Study 272<br>Connectivity<br>Designing the Wireless Campus Network 273<br>The Design Approach 273<br>Field House<br>(Basketball)<br>Liberal Arts<br>Determining the Functional Design<br>Requirements 273<br>Engineering Biological Sciences<br>Tracking the Administration Needs 274<br>Tracking the Athletic Needs 275<br>inistration Building<br>Adm<br>Student Union<br>Tracking the Academic Department<br>Needs 276<br>Internet<br>Tracking Student Union Needs 277<br>200 Meters<br>Tracking Student Needs 277<br>StadiumDorms<br>Constraints and Assumptions 277<br>Identifying the Assumptions 279<br>Identifying the Constraints 281<br>Planning the Equipment Placement:Detailed<br>Design Requirements 283<br>Providing Detailed Administration<br>Requirements 283<br>Providing Detailed Athletic <br>Department Requirements 285<br>Providing Detailed Academic <br>Department Requirements 288<br><br>152_wan_toc 6/22/01 4:54 PM Page xxii<br>xxii Contents<br>Providing Detailed Student Union<br>Department Requirements 290<br>Providing Detailed Student Requirements 291<br>Implementing the Wireless Campus Network 292<br>Implementing the Physical Deployment 293<br>Implementing the Logical Deployment 294<br>Lessons Learned 295<br>Summary 296<br>Solutions Fast Track 297<br>Frequently Asked Questions 299<br>Chapter 9 Designing a Wireless Home <br>Network: Home Office Case Study 301<br>Learn to Build a<br>Introduction 302<br>Wireless Home<br>Network<br>Advantages of a Home Network 302<br>Advantages of a Wireless Home Network 304<br>Assembling the<br>Introducing the Wireless Home Network<br>network components<br>Case Study 305<br>Determining<br>Assessing the Opportunity 305<br>Broadband<br>Defining the Scope of the Case Study 306<br>configuration<br>Designing the Wireless Home Network 306<br>Installing the hardware<br>Determining the Functional Requirements 307<br>Installing and<br>Determining the Needs of Management 307<br>configuring the<br>Determining the Needs of the Family 308<br>software<br>Talking to the IT Department 308<br>Testing the network<br>Creating a Site Survey of the Home 309<br>Assessing the Functional Requirements 310<br>Analyzing the Existing Environment 310<br>Identifying Current Technology Options<br>and Constraints 312<br>Investigating Costs 313<br>Weighing Costs and Benefits 313<br>Assessing the Existing Environment 314<br>Developing a Preliminary Design 315<br>Choosing Vendor Solutions 317<br>Developing a Detailed Design 318<br>Implementing the Wireless Home Network 319<br><br>152_wan_toc 6/22/01 4:54 PM Page xxiii<br>Contents xxiii<br>Assembling the Network Components 319<br>Determining Broadband Configuration 320<br>Installing the Hardware 321<br>Installing and Configuring the Software 322<br>Installing and Configuring the Software<br>for the Home Firewall 322<br>Installing and Configuring the Software<br>for the Wireless Access Point 324<br>Testing the Network 326<br>Designing a Wireless Home Network for Data,<br>Voice,and Beyond 326<br>Current State of the Home Wireless<br>Marketplace 327<br>A Proposed Solution for the Future 329<br>Lessons Learned 330<br>Summary 332<br>Solutions Fast Track 332<br>Frequently Asked Questions 335<br>Designing a Wireless Network Fast Track 337<br>Index 357

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值