Codeforces Round #562 (Div. 2) B. Pairs
链接:https://codeforces.com/contest/1169/problem/B
题意:
Toad Ivan has mm pairs of integers, each integer is between 11 and nn, inclusive. The pairs are (a1,b1),(a2,b2),…,(am,bm)(a1,b1),(a2,b2),…,(am,bm).
He asks you to check if there exist two integers xx and yy (1≤x<y≤n1≤x<y≤n) such that in each given pair at least one integer is equal to xx or yy.
思路:
单独考虑两个完全不相同的对,例如(1,2)-(3,4), 出现这种对时,x和y只能再这两对中取,所以,用vector记录率先出现的一个队,再找没有出现过的队,如果找不到也无所谓,说明一个队里的已经覆盖了全部。
再对这最多四个值进行枚举对,挨个查找。
不过别人思路好像跟我不大一样
代码:
#include <bits/stdc++.h> using namespace std; typedef long long LL;
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
pair<int, int> node[MAXN];
int Dis[MAXN];
int n, m, k, t;
int p, q, u, v;
int x, y, z, w; bool Serch(int a, int b)
{
for (int i = 1;i <= m;i++)
{
if (node[i].first != a && node[i].first != b && node[i].second != a && node[i].second != b)
return false;
}
return true;
} int main()
{
cin >> n >> m;
vector<int> ser;
bool flag = true;
for (int i = 1;i <= m;i++)
{
cin >> node[i].first >> node[i].second;
/*
Dis[node[i].first]++;
if ((Dis[node[i].first] == 1&& flag))
{
ser.push_back(node[i].first);
if (ser.size() == 4)
flag = false;
}
Dis[node[i].second]++;
if ((Dis[node[i].second] == 1&& flag))
{
ser.push_back(node[i].second);
if (ser.size() == 4)
flag = false;
}
*/
if (ser.size() < 4)
{
bool f = true;
for (int j = 0; j < ser.size(); j++)
if (node[i].first == ser[j])
f = false;
for (int j = 0; j < ser.size(); j++)
if (node[i].second == ser[j])
f = false;
if (f)
ser.push_back(node[i].first), ser.push_back(node[i].second);
}
}
flag = false;
// cout << Serch(2, 4) << endl;
// for (auto x:ser)
// cout << x << ' ' ;
// cout << endl;
for (int i = 0;i < ser.size();i++)
for (int j = i+1;j < ser.size();j++)
if (Serch(ser[i], ser[j]))
flag = true;
if (flag)
cout << "YES" << endl;
else
cout << "NO" << endl; return 0;
}
Codeforces Round #562 (Div. 2) B. Pairs的更多相关文章
- Codeforces Round #562 (Div. 2) C. Increasing by Modulo
链接:https://codeforces.com/contest/1169/problem/C 题意: Toad Zitz has an array of integers, each intege ...
- Codeforces Round #562 (Div. 2) A.Circle Metro
链接:https://codeforces.com/contest/1169/problem/A 题意: The circle line of the Roflanpolis subway has n ...
- [Done] Codeforces Round #562 (Div. 2) 题解
A - Circle Metro 模拟几百步就可以了. B - Pairs 爆搜一下,时间复杂度大概是 $O(4 * n)$ Code: 56306723 C - Increasing by Modu ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax(思维题)
Problem Codeforces Round #539 (Div. 2) - C. Sasha and a Bit of Relax Time Limit: 2000 mSec Problem ...
- Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路
Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xx ...
- Codeforces Round #267 (Div. 2) C. George and Job(DP)补题
Codeforces Round #267 (Div. 2) C. George and Job题目链接请点击~ The new ITone 6 has been released recently ...
- Codeforces Round #246 (Div. 2) D. Prefixes and Suffixes
D. Prefixes and Suffixes You have a string s = s ...
- Codeforces Round #272 (Div. 2) 题解
Codeforces Round #272 (Div. 2) A. Dreamoon and Stairs time limit per test 1 second memory limit per ...
随机推荐
- .net中后台c#数组与前台js数组交互
第一步:定义cs数组 cs文件里后台程序中要有数组,这个数组要定义成公共的数组. public string[] lat = null; public string[] lng = null; ...
- springmvc的简单介绍以及springmvc组件的介绍
Spring web mvc框架 什么是springmvc Springmvc是spring框架的一个模块,spring和springmvc无需中间整合层整合 Springmvc是一个基于mvc的we ...
- hdu-5792 World is Exploding(容斥+树状数组)
题目链接: World is Exploding Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Jav ...
- codeforces 569B B. Inventory(水题)
题目链接: B. Inventory time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- STM32中IO口的8中工作模式
该文摘自:http://blog.csdn.net/kevinhg/article/details/17490273 一.推挽输出:可以输出高.低电平,连接数字器件:推挽结构一般是指两个三极管分别受两 ...
- 使用TortoiseGit同步代码到github远程仓库
1.clone github上的代码仓库的URL 可以用HTTPS,SSH, or Subversion 2.同步push 到远程仓库时 要用 SSH地址,同生成SSH private key ,在g ...
- @Autowired的作用,自动装配,省去写get/set方法
这个注解就是spring可以自动帮你把bean里面引用的对象的setter/getter方法省略,它会自动帮你set/get. <bean id="userDao" clas ...
- 设置可见GPU方式
只可见第一块GPU os.environ["CUDA_VISIBLE_DEVICES"] = "0"
- 中国移动推出NB-IoT/eMTC/GSM多模通信模组Qualcomm调制解调器支持
亚洲电子消费展(CES Asia)在上海举行.期间,中国移动正式推出NB-IoT/eMTC/GSM三模通信模组A9500.该通信模组采用Qualcomm MDM9206 LTE IoT调制解调器,具有 ...
- DS:架构-1
ylbtech-DS:架构-1 1. 类库返回顶部 1. 2. 2. 引用返回顶部 1. Api-Base\Common\OAuth2Provider\ServiceBase-OAuth2Provid ...