[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的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...
随机推荐
- MAVN(自动创建maven项目骨架) 项目架构的生成
1.Maven的项目架构生成 A.打开DOS命令窗口选定文件的更跟目录 B:输入命令 mvn archetype:generate C:根据提示输入对应的标识 如图: 最后提示 SUCCESS 即为 ...
- node+express框架中连接使用mysql经验总结
最近在学习node.js,做了一个练手项目,使用node.js+express框架,配合mysql数据库和前端vue框架开发一个多人文档编辑系统. koa,express,node 通用方法连接MyS ...
- 使用maven创建web项目时后面多出来Maven Webapp如何删除
类似这样: 解决办法:
- VR开发2015年终总结
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/50617605 作者:car ...
- JavaScript(DOM编程补充一)
HTML属性的直接调用: 还可以通过getAttribute方法获取属性的值: setAttribute方法: removeAttribute ---------------------------- ...
- CodeForcesGym 100641B A Cure for the Common Code
A Cure for the Common Code Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on ...
- HDU5924 Mr. Frog’s Problem
/* HDU5924 Mr. Frog’s Problem http://acm.hdu.edu.cn/showproblem.php?pid=5924 数论 * */ #include <cs ...
- 洛谷——P1968 美元汇率
https://www.luogu.org/problem/show?pid=1968#sub 题目背景 此处省略maxint+1个数 题目描述 在以后的若干天里戴维将学习美元与德国马克的汇率.编写程 ...
- HDU 4767
昨晚苦恼了一晚,因为即将大三了,必须要准备实习什么的事了.一般都会去公司实习吧,但是看看自己的简历,实在拿不出手,因为大一大二都在搞ACM(虽然真正搞的只有大二一年),但却没有什么成绩,又不愿意做项目 ...
- rails 安装后调整gem sources 地址
rails 安装后调整gem sources 地址 使用https会有认证的问题: 移除原有的: gem sources --remove https://rubygems.org/ 查看当前的: g ...