Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort
题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增
思路:暴力枚举所有可能的列变换 然后在所有可能的情况下求是否存在一种情况可以使每一行最多进行一次交换最后得到严格递增的矩阵
AC代码:
#include "iostream"
#include "stdio.h"
#include "string.h"
using namespace std; int arr[][],n,m;
bool fun(int k)
{
int c=;
for(int i=; i<m; i++)
{
if(arr[k][i] != i+)
c++;
}
if(c== || c==)
return ;
return ;
} int main()
{
int t,r,c,flag,flag0;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=; i<n; i++)
for(int j=; j<m; j++)
cin>>arr[i][j]; for(int i=; i<m; i++)
{
for(int j=; j<m; j++)
{
if(i>j) continue;
for(int k=; k<n; k++)
{
t = arr[k][i];
arr[k][i] = arr[k][j];
arr[k][j] = t;
}
flag=;
flag0=;
for(int k=; k<n; k++)
{
if(!fun(k))
{
flag=;
break;
}
}
if(flag)
{
flag0=;
break;
}
for(int k=; k<n; k++)
{
t = arr[k][i];
arr[k][i] = arr[k][j];
arr[k][j] = t;
}
}
if(flag0)
break;
}
if(flag0)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort的更多相关文章
- CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)
1. Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort 暴力枚举,水 1.题意:n*m的数组, ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)D Dense Subsequence
传送门:D Dense Subsequence 题意:输入一个m,然后输入一个字符串,从字符串中取出一些字符组成一个串,要求满足:在任意长度为m的区间内都至少有一个字符被取到,找出所有可能性中字典序最 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C. Ray Tracing
我不告诉你这个链接是什么 分析:模拟可以过,但是好烦啊..不会写.还有一个扩展欧几里得的方法,见下: 假设光线没有反射,而是对应的感应器镜面对称了一下的话 左下角红色的地方是原始的的方格,剩下的三个格 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) C.Ray Tracing (模拟或扩展欧几里得)
http://codeforces.com/contest/724/problem/C 题目大意: 在一个n*m的盒子里,从(0,0)射出一条每秒位移为(1,1)的射线,遵从反射定律,给出k个点,求射 ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) E. Goods transportation (非官方贪心解法)
题目链接:http://codeforces.com/contest/724/problem/E 题目大意: 有n个城市,每个城市有pi件商品,最多能出售si件商品,对于任意一队城市i,j,其中i&l ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A. Checking the Calendar(水题)
传送门 Description You are given names of two days of the week. Please, determine whether it is possibl ...
- Codeforces Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B. Batch Sort(暴力)
传送门 Description You are given a table consisting of n rows and m columns. Numbers in each row form a ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) B
Description You are given a table consisting of n rows and m columns. Numbers in each row form a per ...
- Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined) A
Description You are given names of two days of the week. Please, determine whether it is possible th ...
随机推荐
- PHP二维数组排序(list_order)
/** * 对二维数组进行排序 * 模拟 数据表记录按字段排序 * * <code> * @list_order($list, $get['orderKey'], $get['orderT ...
- phpcms专题路径修改
两个文件改三处就可以了,既可以后台点击专题列表链接问题,也可以解决生成专题多一个“/”的问题. 1.\phpcms\modules\special\classes\html.class.php大概第1 ...
- JavaScript深入浅出6-函数和作用域
慕课网教程视频地址:Javascript深入浅出 函数的概念:定义一次可调用多次的javascript代码段 创建函数:声明 function fuc(){} 声明前置 表达式 var fuc= ...
- [教程] 【玩转终端1:apt-get】
进来工作比较清闲,所以写点东西,给喜欢折腾的朋友.本文及后面将要介绍的一些终端命令,其实对于玩过linux的人来说,是很基础的东西,我可能是班门弄斧了(拍砖的请轻点,有愿意补充/纠正的,本人求知不得) ...
- NVelocity介绍,NVelocity中文手册文档及实例下载
NVelocity是什么velocity英音:[vi'lɔsiti]美音:[və'lɑsətɪ]近在做一个项目,客户要求有网站模板功能,能够自主编辑网站的风格,因为这个系统是为政府部门做子站系统,举个 ...
- iframe使用方法
--点击按钮会把地址里的页面显示在oframe里,对iframe可以设置宽和高<iframe src="demo_iframe.htm" name="iframe_ ...
- python smtplib email
监控系统需要触发报警邮件, 简单笔记一下的用到的库. smtplib class smtplib.SMTP([host[, port[, local_hostname[, timeout]]]]) 返 ...
- iOS中关于NavigationController中preferredStatusBarStyle一直不执行的问题
重点:真的能改吗?跑起来毛用没有. 1.还要在plist文件里把View controller-based status bar appearance设置成YES. 2.一定要写UINavigatio ...
- Jquery点击本身,修改出本身之外的其他同级元素的样式
1.引用Jquyer库 2.Jquery代码: <script type="text/javascript"> $(function () { slidColor('d ...
- 如何使用videojs兼容IE8浏览器
需要在服务器下运行 首先我们需要下载videojs包 https://github.com/videojs/video.js/releases 这里简单写了一个小栗子 <!DOCTYPE htm ...