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 ...
随机推荐
- JS工具函数汇总
备注:http://phpjs.org/ 这个站点把PHP常用的方法用js实现了,推荐一下 1.从数组中随机获取几个不重复项 //从一个给定的数组arr中,随机返回num个不重复项 function ...
- oracle数据库-备份ORACLE为dmp类型数据
刘备,为自己后期脑子不灵光时可以找个可以翻阅的地方. 一.第一部分导出ORACLE数据 1.数据库地址及账号密码: 数据库地址:10.10.10.132账号密码:oracle/oracle 2.使用X ...
- Servlet_03_部署描述符
二.参考文档 1.Servlet 3.0 之 部署描述符 2.web.xml配置详解 部署描述符文件
- Java丨DBCP连接池完整配置
<!-- 数据源1 --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicData ...
- linux命令学习笔记-kill和killall命令详解
*杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志. 首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令: # kill -pid 注释:标准的kill命令通常都能达到目 ...
- linux 几个逼格高实用的命令
1.xargs [root@gdpsq1x25 log]# find . -type f -name "*.log" |sort -rn./yum.log./sssd/sssd_s ...
- windwos 10 谷歌浏览器出现彩色闪条
应该是上个星期五开始,发现电脑从别的地方切换到谷歌浏览器就会出现闪条,开始也没太注意,但是到周一还是这样,所以再网上查了下, 说什么的都有,什么你按脑屏幕坏了,内存条不行什么是的.后来才发现原来是谷歌 ...
- Elasticsearch搜索引擎版本配置
简要描述: 搜索引擎版本配置 产品 版本号 ES版本要求 说明 PHP =5.5.38 Java =1.8.0_73 用于支持ES Elasticsearch =2.3.5 搜索引擎 ...
- AI-Info-Micron-Insight:通往完全自主之路
ylbtech-AI-Info-Micron-Insight:通往完全自主之路 1.返回顶部 1. 通往完全自主之路 自动驾驶汽车正在从未来梦想演变为当代现实,随着技术成熟,个人和公共交通将永远转变. ...
- maven学习九 关于maven一些參數
一 maven profile: 不同的运行环境,比如开发环境.测试环境.生产环境,而我们的软件在不同的环境中,有的配置可能会不一样,比如数据源配置.日志文件配置.以及一些软件运行过程中的基 ...