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 ...
随机推荐
- openfire性能调优
1. 参考 http://blog.csdn.net/foxisme2/article/details/7521139 http://blog.csdn.net/foxisme2/article/de ...
- overflow:hidden真的失效了吗?
项目中常常有同学遇到这样的问题,现象是给元素设置了overflow:hidden,但超出容器的部分并没有被隐藏,难道是设置的hidden失效了吗? 其实看似不合理的现象背后都会有其合理的解释. 我们知 ...
- leetcode 67. Add Binary (高精度加法)
Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...
- 为什么修改头文件make不重新编译
make是根据依赖文件的时间戳来决定要不要重新编译的.在: object: deplist # actions 中,可以把头文件加进deplist,这样修改头文件后,make就会重新编译了. 单纯地修 ...
- BZOJ2028:[SHOI2009]会场预约(线段树版)
浅谈树状数组与线段树:https://www.cnblogs.com/AKMer/p/9946944.html 题目传送门:https://www.lydsy.com/JudgeOnline/prob ...
- JavaScript:bootstrap 模态框的简单应用
最近用上了bootstrap这个强大的前端框架,有空来总结一下.这里记录下模态框的简单应用. 首先,要在页面中引入相应的js.css文件 <link href="css/bootstr ...
- 六 Vue学习 首页 (下)
一:Store介绍: state: 相当于数据 action: action去commit mutations mutation: 只有mutation 才能改变state 例: const stor ...
- 使用远程线程来注入DLL
使用远程线程来注入DLL DLL注入技术要求我们目标进程中的一个线程调用LoadLibrary来载入我们想要的DLL (1)用OpenProcess函数打开目标进程(2)用VirtualAllocEx ...
- ASP.NET Core依赖注入解读&使用Autofac替代实现【转载】
ASP.NET Core依赖注入解读&使用Autofac替代实现 1. 前言 2. ASP.NET Core 中的DI方式 3. Autofac实现和自定义实现扩展方法 3.1 安装Autof ...
- Linux运行Tomcat下的war文件
1.查看Tomcat进程: ps -ef |grep tomcat 2.关闭Tomcat进程: kill -9 pid 3.关闭Tomcat运行: bin目录下执行 ./shutdown.sh 4. ...