New Year Permutation
来源:互联网 发布:淘宝口令红包怎么抢 编辑:程序博客网 时间:2024/05/17 22:52
一个数列,如果前k个数相等,a[k+1]<b[k+1]那么 a比b好,给出一个矩阵,如果aij=1,那么i和j位置的数是可以交换的,求给出矩阵状态下最好的数列。其实这个比较法就是尽量把小的数放在前面,但是加了一个交换的位置条件。自己想法就是把每个位置遍历,然后把连通分支整个找出来,再内部排序,赋值,接着找下一个连通分支,重复上述动作,循环n次,虽然有点重复,但是只有300个点,并不会超时。话说1A真开心。
#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<queue>using namespace std;int b[303][303];int a[303], leap[303], dp[303];queue<int>p;int main(){int i, j, m, n, ans, temp;char c;cin >> n;for (i = 1; i <= n; i++)cin >> a[i];getchar();for (i = 1; i <= n; i++){for (j = 1; j <= n; j++){c = getchar();b[i][j] = c - '0';}getchar();}for (i = 1; i <= n; i++){p.push(i);memset(leap, 0, sizeof(leap));leap[i] = 1;while (p.size()){temp = p.front();for (j = 1; j <= n; j++){if (b[temp][j] == 1 && !leap[j]){p.push(j);leap[j] = 1;}}p.pop();}ans = 0;for (j = 1; j <= n; j++){if (leap[j]){ans++;dp[ans] = a[j];}}sort(dp + 1, dp + 1 + ans);ans = 0;for (j = 1; j <= n; j++){if (leap[j]){ans++;a[j] = dp[ans];}}}for (i = 1; i <= n; i++)cout << a[i] << " ";cout << endl;return 0;}这是我当时第一次做cf的b题,当时的a题还是50分钟这样做出来的,b题就更不敢奢望了,现在感觉自己有提升,但是 作为一个初学者,想要获得提升是很容易的,还要继续走下去。
0 0
- B - New Year Permutation
- B. New Year Permutation
- CF_500B New Year Permutation
- New Year Permutation
- New Year Permutation
- New Year Permutation
- New Year Permutation
- [CodeForces500B]New Year Permutation[floyd]
- codeforces500b New Year Permutation 【floyd】
- Codeforces 500B - New Year Permutation (思维)
- Good Bye 2014--B. New Year Permutation
- codeforces #500B# New Year Permutation
- Good Bye 2014 B. New Year Permutation
- B. New Year Permutation (CF)
- CF 500B New Year Permutation
- coderforce 500B New Year Permutation
- Codeforces 500B New Year Permutation
- 500B New Year Permutation(Floyd)
- 异常学习笔记
- HBuild+Mui学习笔记(一):真机运行提示错误总结
- JDBC连接数据库后数据库中,中文输出为?,masstive from中文字体变框框的解决方案
- spring 之脱离容器管理创建的对象进行依赖注入
- sas 累加函数
- New Year Permutation
- PHP 发送HTTP请求
- 很久没有写一些东西了,这也许是另外一个开始
- UIButton的一些基本用法
- Android中AsyncTask的分析和使用
- iOS深拷贝和浅拷贝
- Sokcet编程常用函数
- 备战阿里巴巴
- Android中如何查看内存