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

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

#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. maven 依赖的传递性

    1.如图我们有三个项目,项目Age,项目Bge,项目Cge 2.我们使Age项目依赖到Bge项目,Bge项目依赖到Cge项目 Age项目和Bge项目分别执行命令:mvn install  打包*.ja ...

  2. 提高生产力:Web前端验证的标准化

    统一验证标准,减少重复劳动,提高生产力. 当公司内部有多个Web项目的时候,统一验证标准就很有必要了.统一不同项目的验证规则,比如 同为用户名 使用同一套标准,甚至用户名和机构名等也使用同一套标准.( ...

  3. ndk,cygwin编译 .so动态库

    注意: ndk .cygwin 安装路径尽量要和sdk放到一个磁盘里,设置环境变量. 例如D: 根目录  变量名:ndk   值:/cygdrive/d/android-ndk-r8e 打开cygwi ...

  4. 【ACM-ICPC 2018 南京赛区网络预赛 A】An Olympian Math Problem

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 估计试几个就会发现答案总是n-1吧. 队友给的证明 [代码] #include <bits/stdc++.h> #def ...

  5. redis helloworld

    一.启动 redis 服务 [root@MyLinux bin]# ./redis-server redis.conf 二.使用客户端连接服务 [root@MyLinux bin]# ./redis- ...

  6. 获取DATA的数据

    num=DataTable("参数名",dtGlobalSheet) 'systemutil.Run "C:\Program Files (x86)\HP\QuickTe ...

  7. nyoj 119 士兵杀敌(三) 【线段树】【单点更新】

    题意:. .. 策略如题. 思路:我们先如果仅仅求某一区间的最大值.我们仅仅须要利用线段树的模板.仅仅须要初始化和询问的时候小小的改动一下.改成祖先结点储存的不再是子节点的和而是两个子节点之间的最大值 ...

  8. HDU 1113 Word Amalgamation (map 容器 + string容器)

    http://acm.hdu.edu.cn/showproblem.php?pid=1113 Problem Description In millions of newspapers across ...

  9. mysqlbinlog高速遍历搜索记录

    目标,开发者说有个数据莫名其妙加入了.可是不知道是从哪里加入的.并且应用功能里面不应该加入这种数据,为了查清楚来源,所以我就准备去binlog里面找了.可是binlog有好几个月的数,我这样一个个my ...

  10. hdoj--5240--Exam()

    Exam Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...