[CodeForces]500B New Year Permutation
刷水题做几道入门贪心题预热。。。
找联通块里字典序最小的放到最前面即可。记得写传递闭包
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N=350;
int n,a[N],pos[N],g[N][N];
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]),pos[a[i]]=i;
char c[1100];
for(int i=1;i<=n;i++) {
scanf("%s",c);
g[i][i]=1;
for(int j=1;j<=n;j++) {
if(c[j-1]=='1') g[i][j]=1;
}
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
g[i][j]|=g[i][k]&g[k][j];
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
if(g[i][pos[j]]) {
a[i]=j;
pos[j]=0;
break;
}
}
}
for(int i=1;i<=n;i++) printf("%d ",a[i]);
}
[CodeForces]500B New Year Permutation的更多相关文章
- Codeforces 500B. New Year Permutation[连通性]
B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- codeforces 500B.New Year Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...
- Codeforces 500B New Year Permutation( Floyd + 贪心 )
B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 691D Swaps in Permutation
Time Limit:5000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Status Prac ...
- codeforces B. Levko and Permutation 解题报告
题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...
- 【搜索】【并查集】Codeforces 691D Swaps in Permutation
题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...
- [Codeforces 864D]Make a Permutation!
Description Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to ...
- Codeforces 785E. Anton and Permutation
题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...
- Codeforces 804E The same permutation(构造)
[题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...
随机推荐
- Project Euler 32 Pandigital products
题意:找出所有形如 39 × 186 = 7254 这种,由 1 - 9,9个数字构成的等式的和,注意相同的积不计算两次 思路:如下面两种方法 方法一:暴力枚举间断点 /*************** ...
- 【LibreOJ 6278】 数列分块入门 2 (分块)
题目原址 给出一个长为n的数列,以及n个操作,操作涉及区间加法,询问区间内小于某个值x的元素个数. code: #include<cstdio> #include<iostream& ...
- [HEOI2013]Eden 的新背包问题
数据极水,不加优化的多重背包都能过...早知道考试的时候不加奇奇怪怪的卡常优化,卡了45分... 就是从前往后做一个多重背包,从后往前再做一个,问的时候就暴力求一下跳过这个的最佳方案... #incl ...
- [NoiPlus2016]换教室
flag++ //Writer : Hsz %WJMZBMR%tourist%hzwer #include <iostream> #include <cstdio> #incl ...
- 4.1、Ansible模块
ansible-doc -l 列出所有模块 ansible-doc 模块名 查看模块的help说明 ansible-doc -s module_name:获取指定模块的使用信息 ***文 ...
- ubuntu 下jrtplib编译
我本来想用最新的 jrtplib-3.9.1和jthread-1.3.1,可是最新的那两个版本中都是用cmake进行配置的,我搞了好久,查了好多资料也没有解决交叉编译的问题,无奈,只能选用比较老的两个 ...
- el表达式中的比较和包含
相等( equal ) :eq 不相等( not equal ): ne / neq 大于( greater than ): gt 小于( less than ): lt 大于等于( great th ...
- 洛谷 1262 间谍网络 Tarjan 图论
洛谷 1262 图论 tarjan 并不感觉把这道题目放在图的遍历中很合适,虽然思路比较简单但是代码还是有点多的,, 将可收买的间谍的cost值设为它的价格,不可购买的设为inf,按照控制关系连图,T ...
- _DataStructure_C_Impl:AOE网的关键路径
//_DataStructure_C_Impl:CriticalPath #include<stdio.h> #include<stdlib.h> #include<st ...
- nginx的安装步骤
nginx学习资料;https://zhuanlan.zhihu.com/p/34943332 1.下载nginx的安装包:https://nginx.org/en/download.html 2. ...