刷水题做几道入门贪心题预热。。。

找联通块里字典序最小的放到最前面即可。记得写传递闭包

#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的更多相关文章

  1. Codeforces 500B. New Year Permutation[连通性]

    B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  2. codeforces 500B.New Year Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/500/B 题目意思:给出一个含有 n 个数的排列:p1, p2, ..., pn-1, pn.紧接着是一个 ...

  3. Codeforces 500B New Year Permutation( Floyd + 贪心 )

    B. New Year Permutation time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. Codeforces 691D Swaps in Permutation

    Time Limit:5000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Prac ...

  5. codeforces B. Levko and Permutation 解题报告

    题目链接:http://codeforces.com/problemset/problem/361/B 题目意思:有n个数,这些数的范围是[1,n],并且每个数都是不相同的.你需要构造一个排列,使得这 ...

  6. 【搜索】【并查集】Codeforces 691D Swaps in Permutation

    题目链接: http://codeforces.com/problemset/problem/691/D 题目大意: 给一个1到N的排列,M个操作(1<=N,M<=106),每个操作可以交 ...

  7. [Codeforces 864D]Make a Permutation!

    Description Ivan has an array consisting of n elements. Each of the elements is an integer from 1 to ...

  8. Codeforces 785E. Anton and Permutation

    题目链接:http://codeforces.com/problemset/problem/785/E 其实可以CDQ分治... 我们只要用一个数据结构支持单点修改,区间查询比一个数大(小)的数字有多 ...

  9. Codeforces 804E The same permutation(构造)

    [题目链接] http://codeforces.com/contest/804/problem/E [题目大意] 给出一个1到n的排列,问每两个位置都进行一次交换最终排列不变是否可能, 如果可能输出 ...

随机推荐

  1. [SDOI2018]战略游戏(圆方树+虚树)

    喜闻乐见的圆方树+虚树 图上不好做,先建出圆方树. 然后答案就是没被选到的且至少有两条边可以走到被选中的点的圆点的数量. 语文不好,但结论画画图即可得出. 然后套路建出虚树. 发现在虚树上DP可以得出 ...

  2. nyoj312-20岁生日

    20岁生日 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 路过这的20岁生日就要到了,他当然很开心,可是他突然想到一个问题,是不是每个人从出生开始,到达20岁生日时所经 ...

  3. nlogn求逆序对&&陌上花开

    前置: nlogn逆序对: 前一个小时我还真的不会这个Orz 这里运用归并排序的思想. 对于一个序列,我们把它先分开,再合并成一个有序序列. 引自https://blog.csdn.net/qq_30 ...

  4. uni-app 路由navigate

    uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台. 公司最近在写APP应用到了uni-app  我在写的时 ...

  5. jQuery练习总结(一)

    第一个jQuery程序: 注意:使用jQuery时候定义单击事件使用的方法是click(function(){处理单击事件产生时所要执行的代码}) , 而JavaScript定义的单击事件则是 xx. ...

  6. PatentTips - Uncore thermal management

    BACKGROUND The field of invention relates to the computer sciences, generally, and, more specificall ...

  7. java spring中对properties属性文件加密及其解密

    http://blog.csdn.net/yaerfeng/article/details/26561791

  8. 洛谷—— P1457 城堡 The Castle

    https://www.luogu.org/problem/show?pid=1457 题目描述 我们憨厚的USACO主人公农夫约翰(Farmer John)以无法想象的运气,在他生日那天收到了一份特 ...

  9. Xshell 访问虚拟机中linux

    .关闭linux防火墙 service iptables stop chkconfig iptables off .启动ssh服务 service sshd start

  10. HDU 2553 N皇后问题 (DFS_回溯)

    Problem Description 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即随意2个皇后不同意处在同一排,同一列,也不同意处在与棋盘边框成45角的斜线上. 你的任务是.对于给定的N ...