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 ...
随机推荐
- JNDI数据源配置
一.数据源的由来 在Java开发中,使用JDBC操作数据库的四个步骤如下: ①加载数据库驱动程序(Class.forName("数据库驱动类");) ②连接数据库(Connec ...
- springmvc的简单介绍以及springmvc组件的介绍
Spring web mvc框架 什么是springmvc Springmvc是spring框架的一个模块,spring和springmvc无需中间整合层整合 Springmvc是一个基于mvc的we ...
- 二:apache的Qpid消息中间件介绍
一:什么是Qpid?--->Qpid 是 Apache 开发的一款面向对象的消息中间件,它是一个 AMQP 的实现,可以和其他符合 AMQP 协议的系统进行通信.--->Qpid 提供了 ...
- NodeJS测试实例
实例一: 先来个简单的实例,把下面的代码保存为main.js,让自己欣喜下: var http = require("http"); function onRequest(requ ...
- MVC之一、预备知识储备
自动属性 隐式类型 对象初始化器与集合初始化器 匿名类 扩展方法 Lambda表达式 (1).自动属性(Auto-Implemented Properties) C#自动属性可以避免原来这样我们手工声 ...
- puppet初始化安装和配置(puppet自动化系列1)
一.服务器规划 以下均直接yum安装最新版. 服务器操作系统为centos6.2 Puppetmaster1 10.168.32.116 puppstmaster1.jq.com Puppetmast ...
- lwip【6】LWIP使用经验
LWIP使用经验 一 LWIP内存管理 LWIP的内存管理使用了2种方式:内存池memp和内存堆mem,如图1所示. 内存池的特点是预先开辟多组固定大小的内存块组织成链表,实现简单,分配和回收速度快, ...
- js能否实现截图,截图之后的图片数据再下载到本地?
https://www.zhihu.com/question/20763177 http://www.cnblogs.com/yanweidie/p/5203943.html
- Spring:JdbcTemplate使用指南
Spring:JdbcTemplate使用指南 Spring:JdbcTemplate使用指南 前言: 本文指在介绍Spring框架中的JdbcTemplate类的使用方法,涉及基本的Spring反转 ...
- TypeScript完全解读(26课时)_汇总贴
ECMAScript 6 入门:http://es6.ruanyifeng.com/ 官网:http://www.typescriptlang.org/ 中文网:https://www.tslang. ...