枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution
#include <iostream>
#include <cstdio>
using namespace std;
int n, m;
int a[][];
bool check(int t)//检查第t行是否符合递增
{
int flag = ;
for(int i = ; i < m; i++)
if(a[t][i] < a[t][i - ]) {flag = ; break;}
if(!flag) return false;
return true;
}
void swapcolumn(int x, int y)//交换两列
{
int tmp[];
for(int i = ; i < n; i++)
{
tmp[i] = a[i][x];
a[i][x] = a[i][y];
a[i][y] = tmp[i];
}
return;
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = ; i < n; i++)
for(int j = ; j < m; j++)
scanf("%d", &a[i][j]);
int flag[], ff = , res = ;
for(int i = ; i < n; i++) flag[i] = ;
for(int p = ; p < m; p++)
{
for(int q = p; q < m; q++)
{
for(int i = ; i < n; i++) flag[i] = ;
ff = ;
swapcolumn(p, q);
for(int t = ; t < n; t++)
{
for(int i = ; i < m; i++)
{
for(int j = i; j < m; j++)
{
swap(a[t][i], a[t][j]);
if(check(t)) flag[t] = ;
swap(a[t][i], a[t][j]);//如果这两个交换不行,就把它俩换回来
}
}
}
for(int i = ; i < n; i++)
if(!flag[i]) {ff = ; break;}
if(ff) res = ;//res记录最终结果
swapcolumn(p, q);
}
}
if(!res) printf("NO\n");
else printf("YES\n");
return ;
}
枚举 || CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution的更多相关文章
- CodeForces 742B Arpa’s obvious problem and Mehrdad’s terrible solution (暴力枚举)
题意:求定 n 个数,求有多少对数满足,ai^bi = x. 析:暴力枚举就行,n的复杂度. 代码如下: #pragma comment(linker, "/STACK:1024000000 ...
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution —— 异或
题目链接:http://codeforces.com/contest/742/problem/B B. Arpa's obvious problem and Mehrdad's terrible so ...
- Codeforces Round #383 (Div. 2) B. Arpa’s obvious problem and Mehrdad’s terrible solution
B. Arpa’s obvious problem and Mehrdad’s terrible solution time limit per test 1 second memory limit ...
- 【codeforces 742B】Arpa’s obvious problem and Mehrdad’s terrible solution
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Arpa’s obvious problem and Mehrdad’s terrible solution 思维
There are some beautiful girls in Arpa’s land as mentioned before. Once Arpa came up with an obvious ...
- B. Arpa’s obvious problem and Mehrdad’s terrible solution
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- CF742B Arpa's obvious problem and Mehrdad's terrible solution 题解
Content 有一个长度为 \(n\) 的数组,请求出使得 \(a_i \oplus a_j=x\) 且 \(i\neq j\) 的数对 \((i,j)\) 的个数.其中 \(\oplus\) 表示 ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths(启发式合并)
codeforces 741D Arpa's letter-marked tree and Mehrdad's Dokhtar-kosh paths 题意 给出一棵树,每条边上有一个字符,字符集大小只 ...
- codeforces 741D Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths
题目链接:Arpa’s letter-marked tree and Mehrdad’s Dokhtar-kosh paths 第一次写\(dsu\ on\ tree\),来记录一下 \(dsu\ o ...
随机推荐
- js 排列 组合
<script> //组合 function C(arr, num){ var r=[]; (function f(t,a,n){ if (n==0) return r.push(t); ...
- WebService安全解决方案—简单握手协议
具体方案如下图: 2.解决方案分析 A.SiteA每次向SiteB发送的请求参数都不一样,造成伪造者难以模仿和推敲里面的算法过程. B.伪造者获得了SayHelloRequest的数据,它向SiteB ...
- Python学习之旅—生成器与迭代器案例剖析
前言 前面一篇博客笔者带大家详细探讨了生成器与迭代器的本质,本次我们将实际分析一个具体案例来加深对生成器与迭代器相关知识点的理解. 本次的案例是一个文件过滤操作,所做的主要操作就是过滤出一个目录下的文 ...
- Spring boot 启动报错:com.mongodb.MongoSocketOpenException: Exception opening socket
详细错误信息: com.mongodb.MongoSocketOpenException: Exception opening socket at com.mongodb.connection.Soc ...
- UVa 1643 Angle and Squares (计算几何)
题意:有n个正方形和一个角(均在第一象限中),使这些正方形与这个角构成封闭的阴影区域,求阴影区域面积的最大值. 析:很容易知道只有所有的正方形的对角形在一条直线时,是最大的,然后根据数学关系,就容易得 ...
- E20170510-hm
prototype n. 原型,雏形,蓝本; omit (omitted) vt. 省略; 遗漏; autonomous adj. 自治的; 有自主权的; fold ...
- 老天待我不薄,又来这么一题POJ1753
还是位运算+BFS系列题: 现在这种真是无比喜欢,今天搞了一上午这题...因为状态的改变写错了-T.T #include<cstdio> #include<queue> #in ...
- Luogu P1156 垃圾陷阱 【dp】By cellur925
题目传送门 这题...看上去浓浓的背包气息...但是并不好设计状态啊emmm. 我们考虑可能成为状态的量:高度.血量.时间.物品.看数据范围也猜到应该大概是个二维dp了w. 正确的状态设计之一:设$f ...
- Contest Hunter 0103最短Hamilton路径 【状压dp】 By cellur925
题目传送门 Hamilton路径的定义:从0(起点)到n-1(终点)不重不漏地经过每个点恰好一次. 由于数据范围非常小,考虑状压.如NOIP2017宝藏一题,把状态压缩设为n个点是否已到达的二进制数. ...
- linux虚拟机时间不准的问题
如果时区不准, 使用tzselect命令(timezone选择),选择北京时间.然后把输出的命令写入/etc/profile.d/time.sh里. 然后用crontab写定时任务,每天执行一次. 3 ...