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 ...
随机推荐
- PYTHON 爬虫笔记六:PyQuery库基础用法
知识点一:PyQuery库详解及其基本使用 初始化 字符串初始化 html = ''' <div> <ul> <li class="item-0"&g ...
- ultraedit激活
使用期满的解决办法:https://blog.csdn.net/dfh00l/article/details/52093630 下载:https://blog.csdn.net/qq_16093323 ...
- 农业公司flash动画模板
农业公司flash动画素材下载模板是一款绿色水果蔬菜种植企业的flash动画模板. 下载:http://www.huiyi8.com/sc/10576.html
- Vagrant + Vbox实战 【转】
原文地址:http://www.cnblogs.com/suihui/p/4362233.html 一.软件下载 1.下载Oracle VM VirtualBox https://www.virtua ...
- [转]Javascript高性能动画与页面渲染
No setTimeout, No setInterval 作者 李光毅 发布于 2014年4月30日 如果你不得不使用setTimeout或者setInterval来实现动画,那么原因只能是你需要精 ...
- bzoj 3653 谈笑风生——主席树
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3653 原来一直想怎么线段树合并.可是不会把角标挪一位. 查询的其实是子树内一段深度的点的 s ...
- 洛谷 P4336 黑暗前的幻想乡 —— 容斥+矩阵树定理
题目:https://www.luogu.org/problemnew/show/P4336 当作考试题了,然而没想出来,呵呵. 其实不是二分图完美匹配方案数,而是矩阵树定理+容斥... 就是先放上所 ...
- linux历史及基本知识
1. Linux的历史: 1973年,Ken Thompson以C语言写出第一个正式版的UNIX内核, 1977年:重要的UNIX分支——BSD(Berkeley Sofeware Distribut ...
- Code:获取指定汉字的首字母
ylbtech-Code:获取指定汉字的首字母 1.获取指定汉字的首字母返回顶部 1. /// <summary> /// 获取指定汉字的首字母 /// </summary> ...
- sql web Admin 源码.net 升级
http://www.cnblogs.com/foundation/archive/2008/10/07/1305297.html