[Codeforces Round #816 (Div. 2)] D. 2+ doors
这次Div.2比之前我打的有些要难啊,前三道题就耗了好多时间,D题干脆摆烂了。。。
还是太逊了
对于一个\(x\),有\(x|y_i=z_i\),那么我们设\(num[x]=z_1\)&\(z_2\)&\(z_3\)....
若\(z_i\)的第\(pos\)位为0,则说明\(x\)与\(y_i\)的第\(pos\)位一定为0;若\(z_i\)的第\(pos\)位为0,则说明\(x\)与\(y_i\)第pos至少 有一个为1,即\(x\)的第\(pos\)位可能为1,\(y_i\)的第\(pos\)位可能为1
所以,对于初始的\(num[x]\),它就是第\(x\)个数的所有答案中最大的
既然答案要求字典序最小,那么遍历第一个数到最后一个数,将当前数记为\(x\),将所有与\(x\)有题目给定的关系的\(y\)与\(z\)都遍历一遍,记 \(t|=z_i\)&(~\(num[y_i]\))
\(z_i\)&(~\(num[y_i]\))显然意味着在当前这个关系中,\(x\)必须取到的1
所以\(t|=z_i\)&(~\(num[y_i]\))也就意味这对于\(x\)的所有关系,\(x\)必须取的数
前文说了对于初始的\(num[x]\),它是第\(x\)个数的所有答案中最大的,所以这时求出的\(t\)也一定 是第一个数最小的答案
再将\(num[x]\)更新为\(t\),继续上述过程,得到的就是字典序最小的答案
#include<bits/stdc++.h>
#define pr pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,M=2e5+5;
int n,q,num[N];
vector<pr> cdt[N];
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i) num[i]=(1<<30)-1;
for(int i=1,x,y,z;i<=q;++i){
scanf("%d%d%d",&x,&y,&z);
num[x]&=z,num[y]&=z;
cdt[x].push_back(pr(y,z));
cdt[y].push_back(pr(x,z));
}
for(int i=1;i<=n;++i){
int t=0;
for(int j=0;j<cdt[i].size();++j){
int x=cdt[i][j].fi,s=cdt[i][j].se;
t|=(s&(~num[x]));
if(x==i){ t=s; break; }
}
printf("%d ",(num[i]=t));
}
return 0;
}
[Codeforces Round #816 (Div. 2)] D. 2+ doors的更多相关文章
- Codeforces Round #549 (Div. 2)A. The Doors
A. The Doors time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- Codeforces Round #816 (Div. 2)/CodeForces1715
CodeForces1715 Crossmarket 解析: 题目大意 有一个 \(n \times m\) 的空间,Stanley 需要从左上角到右下角:Megan 则需要从左下角到右上角.两人可以 ...
- Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题
Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec Memory Limit: 256 MBSubmit: xxx ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
- Codeforces Round #368 (Div. 2)
直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- Codeforces Round #279 (Div. 2) ABCDE
Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems # Name A Team Olympiad standard input/outpu ...
随机推荐
- AI带你省钱旅游!精准预测民宿房源价格!
作者:韩信子@ShowMeAI 数据分析实战系列:https://www.showmeai.tech/tutorials/40 机器学习实战系列:https://www.showmeai.tech/t ...
- 题解 P6745 『MdOI R3』Number
前言 不知道是不是正解但是觉得挺好理解. 科学计数法 将一个数表示为\(a\times 10^x\) 的形式.其中\(a\leq10\),\(x\) 为整数. \(\sf Solution\) 其实这 ...
- TensorFlow?PyTorch?Paddle?AI工具库生态之争:ONNX将一统天下
作者:韩信子@ShowMeAI 深度学习实战系列:https://www.showmeai.tech/tutorials/42 本文地址:https://www.showmeai.tech/artic ...
- 将Oracle数据库迁移到达梦数据库
公司某产品在项目现场上常用到的数据库有Oracle和达梦. 做性能测试需要根据项目现场预埋大量的基础数据和业务数据,耗费时间.精力.故完成Oracle数据库的性能测试之后,采用直接将Oracle数据库 ...
- getAddress和getHostAddress的区别
getAddress方法和getHostAddress类似,它们的唯一区别是getHostAddress方法返回的是字符串形式的IP地址,而getAddress方法返回的是byte数组形式的IP地址.
- C#之GCHandle
转载 略谈GCHandle C# - Marshal.StructureToPtr方法简介 Marshal类 两个方法StructureToPtr和PtrToStructure实现序列化 字节 数组 ...
- 【Java并发009】原理层面:ThreadLocal类全解析
一.前言 在Java多线程模块中,ThreadLocal是比较重要的知识点,虽然ThreadLocal类位于java.lang包,但是这个类基本上仅用于多线程. 二.ThreadLocal类概要 2. ...
- 【Spring系列】- Spring事务底层原理
Spring事务底层原理 生命不息,写作不止 继续踏上学习之路,学之分享笔记 总有一天我也能像各位大佬一样 一个有梦有戏的人 @怒放吧德德 分享学习心得,欢迎指正,大家一起学习成长! 目录 Sprin ...
- ValueError: Detected newline in header value. This is a potential security problem
原因 flask框架进行重定向的url中包含 换行符\n或\r 解决方法 使用 strip() 函数去除行首或行尾的换行符(如果你url中间包含这些符号replace函数替换, 但是如果中间包含只能说 ...
- 1. PyQt5开发环境的搭建
专栏地址 ʅ(‾◡◝)ʃ 因为我个人使用的是 Linux 还有之前用过Windows 没用过 Mac 所以这里我简单结束 Linux 和 Windows 开发环境的搭建 Windows 开发PyQt5 ...