Codeforces Round #677 (Div. 3) D. Districts Connection思维1200
题目链接 Problem - 1433D - Codeforces
题目
美好的一天,从看不懂题目开始~~

4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
YES
1 3
3 5
5 4
1 2
NO
YES
1 2
2 3
3 4
YES
1 2
1 3
1 4
题意
给n个区域,用n-1个路把它们连起来,使每个地方都能到达其它任何地方
但是呢,每个区域都属于一个组织,不能让两个相同的组织直接相连
解析
想到了就很容易过的,比如说拿1当中介,所有的与1不同组织的区域都和1相连,与1同组织的与temp相连
其中temp=“和1非同组织的序号”
AC代码
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std; typedef long long ll; int a[5010]; int main()
{
int t;
cin >> t;
while(t --)
{
int n;
cin >> n;
int lag = 0;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
if(i!= 1 && a[i] != a[1])
lag = i;
}
if(lag==0)
cout << "NO" << endl;
else
{
cout << "Yes" << endl;
for(int i = 2; i <= n; i ++)
if(a[i] != a[1])
cout << 1 << ' ' << i << endl;
else cout << i << ' '<< lag << endl;
}
}
return 0;
}
英语小芝士
district 区域,地方
distinct 不同的,清楚的,明显的
gang 伙,群,组织
输出部分的:
Each road should be presented as a pair of integers xi and yi (1≤xi,yi≤n;xi≠yi1≤xi,yi≤n;xi≠yi), where xi and yi are two districts the i-th road connects.
每条路都应该用一对整数xi,yi表示, xi,yi是不同的区域
Codeforces Round #677 (Div. 3) D. Districts Connection思维1200的更多相关文章
- Codeforces Round #677 (Div. 3) 题解
Codeforces Round #677 (Div. 3) 题解 A. Boring Apartments 题目 题解 简单签到题,直接数,小于这个数的\(+10\). 代码 #include &l ...
- Codeforces Round #677 (Div. 3)【ABCDE】
比赛链接:https://codeforces.com/contest/1433 A. Boring Apartments 题解 模拟即可. 代码 #include <bits/stdc++.h ...
- Codeforces Round #677 (Div. 3) D/1433D Districts Connection
https://codeforces.com/contest/1433/problem/D 找两个不同权值的节点A.B连起来,所有与A不同权值的连到A上,相同的连到B上. #include<io ...
- Codeforces Round #677 (Div. 3) E、G题解
E. Two Round Dances #圆排列 题目链接 题意 \(n\)(保证偶数)个人,要表演一个节目,这个节目包含两种圆形舞蹈,而每种圆形舞蹈恰好需要\(n/2\)个人,每个人只能跳一种圆形舞 ...
- Codeforces Round #677 (Div. 3) G. Reducing Delivery Cost(dijkstra算法)
题目链接:https://codeforces.com/contest/1433/problem/G 题解 跑 \(n\) 遍 \(dijkstra\) 得到任意两点间的距离,然后枚举哪一条边权为 \ ...
- Codeforces Round #677 (Div. 3)
F. Zero Remainder Sum || dp #include <cstdio> #include <algorithm> #include <cstring& ...
- Codeforces Round #353 (Div. 2) C. Money Transfers (思维题)
题目链接:http://codeforces.com/contest/675/problem/C 给你n个bank,1~n形成一个环,每个bank有一个值,但是保证所有值的和为0.有一个操作是每个相邻 ...
- Codeforces Round #517 (Div. 2) C. Cram Time(思维+贪心)
https://codeforces.com/contest/1065 题意 给你a,b,让你找尽量多的自然数,使得他们的和<=a,<=b,用在a和b的自然数不能重复 思路 假如只有一个数 ...
- Divide by Zero 2021 and Codeforces Round #714 (Div. 2) B. AND Sequences思维,位运算 难度1400
题目链接: Problem - B - Codeforces 题目 Example input 4 3 1 1 1 5 1 2 3 4 5 5 0 2 0 3 0 4 1 3 5 1 output 6 ...
随机推荐
- vim设置自动添加头部注释
#自己改了改vim开头文件,如下图# 友友们可以直接修改·SetTitle() if v:lang =~ "utf8$" || v:lang =~ "UTF-8$&quo ...
- 详解数据库三种删除方法: delete drop truncate
Delete Delete :删除数据表中的行(可以删除某一行,也可以在不删除数据表的情况下删除所有行). 删除某一行:Delete from 数据表名称 where 列名称=值: 删除所有行:Del ...
- HashMap集合类 5种最佳遍历方式
1. 使用 Iterator 遍历 HashMap EntrySet 2. 使用 Iterator 遍历 HashMap KeySet 3. 使用 For-each 循环迭代 HashMap 4. 使 ...
- 用ssh无密码登录远程linux
登录linux常用的方式是:用户名+密码,多次输入密码非常不方便,所以推荐使用密钥登录,安全又方便,下面我说下怎么使用密钥登录. 生成密钥 使用密钥登录首先需要本地有ssh密钥 如果本地没有密钥,那么 ...
- 还在担心CC攻击? 让我们来了解它, 并尽可能将其拒之服务之外.
还在担心CC攻击? 让我们来了解它, 并尽可能将其拒之服务之外. CC攻击是什么? 基本原理 CC原名为ChallengeCollapsar, 这种攻击通常是攻击者通过大量的代理机或者肉鸡给目标服务器 ...
- python 列表,字典,元组,字符串,QuerySet之间的相互转换
1. 列表转换成字典list1 = ['key1','key2','key3']list2 = ['value1','value2'] dict1 = zip(list1,list2) # dict( ...
- SpringBoot Jpa 双数据源mysql + oracle + liquibase+参考源码
一.yml文件配置 spring: # 数据库配置 datasource: primary: jdbc-url: jdbc:mysql://localhost:3306/mes-dev?useUnic ...
- 客户端注册 Watcher 实现 ?
1.调用 getData()/getChildren()/exist()三个 API,传入 Watcher 对象 2.标记请求 request,封装 Watcher 到 WatchRegistrati ...
- Myql 中的事务回滚机制概述 ?
事务是用户定义的一个数据库操作序列,这些操作要么全做要么全不做,是一个 不可分割的工作单位,事务回滚是指将该事务已经完成的对数据库的更新操作撤 销.要同时修改数据库中两个不同表时,如果它们不是一个事务 ...
- spring-boot-关于配置文件
------------恢复内容开始------------ spring-boot 的配置文件有四个地方: 项目更目录下的config目you录下(自己建) 项目根目录下 resource 目录下的 ...