枚举 || 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 ...
随机推荐
- LRESULT 数据类型
MSDN: Signed result of message processing. This type is declared in WinDef.h as follows: typedef LON ...
- 任务46:Identity MVC:登录逻辑实现
任务46:Identity MVC:登录逻辑实现 实现登陆的方法 退出方法 _layout里面增加如下的代码: Login.cshtml 运行代码测试: 这个地方的单词之前拼错了.这里进行修正 输入账 ...
- typeof操作符返回一个字符串,表示未经计算的操作数的类型。
typeof操作符返回一个字符串,表示未经计算的操作数的类型. 语法 typeof运算符后跟操作数: typeof operand or typeof (operand) 参数 operand 是 ...
- 网易蜂巢(云计算基础服务)MongoDB服务重磅来袭
此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MongoDB是目前最为流行的NoSQL数据库,在2017年1月新鲜出炉的数据库权威排行榜上,MongoDB ...
- Codeforces - 9D - How many trees? - 简单dp - 组合数学
https://codeforces.com/problemset/problem/9/D 一开始居然还想直接找公式的,想了想还是放弃了.原来这种结构是要动态规划. 状态是知道怎么设了,$t_{nh} ...
- springboot redis工具类
package com.vv.boot.util; import java.util.List; import java.util.Map; import java.util.Set; import ...
- WPF DataGrid foreground 绑定问题
初学WPF , 希望对DataGrid 中所属的一个Column名下的值的颜色动态修改 <DataGridTextColumn Header="隐含回购利率(%)" Bin ...
- spring-data-redis 使用过程中踩过的坑
spring-data-redis简介 Spring-data-redis是spring大家族的一部分,提供了在srping应用中通过简单的配置访问redis服务,对reids底层开发包(Jedis, ...
- Python中lambda表达式的应用
lambda表达式 Python中定义了一个匿名函数叫做lambda表达式,个人理解实现的作用就是代替一些简单的函数,使得代码看上去更简洁并且可读性高.举个例子,我们有一个元组列表[(‘a’,1),( ...
- AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...