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的数组,每行最多可交换1次,列最多可交换两列,问最终是否可以变换到每行都是1~m。
2、总结:暴力即可。
#include<bits/stdc++.h>
#define F(i,a,b) for (int i=a;i<b;i++)
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int N=,MAX=;
int n,m,flag;
int a[][],vis[]; void exchange(int i,int j)
{
int t;
FF(l,,n){
t=a[l][i],a[l][i]=a[l][j],a[l][j]=t;
}
} int is()
{
int num=;
FF(l,,n){
num=;
FF(i,,m){
if(a[l][i]!=i){
num++;
if(num>){return ;}
}
}
}
return ;
} void solve()
{
if(is()){flag=;return ;}
FF(i,,m-)FF(j,i+,m)
{
exchange(i,j);
if(is()){flag=;return ;}
exchange(i,j);
}
} int main()
{
while(~scanf("%d%d",&n,&m))
{
FF(i,,n)FF(j,,m)cin>>a[i][j];
flag=;
solve();
if(flag)puts("YES");
else puts("NO");
} return ;
}
D. Dense Subsequence 暴力枚举
1、题意:小写字母组成的字符串中选出一些位置,使得任意的间距为m的区间至少要有一个字符被选出。字典序最小输出。
2、总结:看了题解,原来还是暴力枚举
2、思路:在26个小写字母中,如果选出了ch,那么比ch小的字母都要选才可保证字典序最小。所以,假设选出的字母中最大的是ch,只要搜出ch最少需要多少个即可。也就是对26个字母逐一搜一遍。
#include<bits/stdc++.h>
#define F(i,a,b) for (int i=a;i<b;i++)
#define FF(i,a,b) for (int i=a;i<=b;i++)
#define mes(a,b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int N=,MAX=; int m,len;
char str[N]; int solve(int ans)
{
int pre=-,now=-,num=;
F(i,,len){
if(str[i]-'a'<=ans){
now=i;
if(str[i]-'a'<ans)pre=i;
}
if(i-pre==m) {
if(now>pre) num++,pre=now;
else return -;
}
}
return num;
} int main()
{
scanf("%d%s",&m,str);
len=strlen(str);
int vis[]; mes(vis,);
F(i,,len) vis[str[i]-'a']++;
F(i,,){
int flag=solve(i);
if(flag!=-){
F(j,,i)F(l,,vis[j]){
printf("%c",'a'+j);
}
F(j,,flag) printf("%c",'a'+i);
puts("");
break;
} } return ;
}
CF Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)的更多相关文章
- 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) B. Batch Sort
链接 题意:输入n,m,表示一个n行m列的矩阵,每一行数字都是1-m,顺序可能是乱的,每一行可以交换任意2个数的位置,并且可以交换任意2列的所有数 问是否可以使每一行严格递增 思路:暴力枚举所有可能的 ...
- 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 ...
随机推荐
- MRDS学习二——机械车
准备机械车: 第一步:从Service中选择一个Generic Differential Drive (通用差速驱动:同一轴的左右轮胎可以转动不同速度的车子)放入Diagram中. 第二步:对其进行配 ...
- PHP之static静态变量详解(一)
什么是static静态变量?(以下为在C语言中的理解) 静态变量 类型说明符是static. 静态变量属于静态存储方式,其存储空间为内存中的静态数据区(在静态存储区内分配存储单元),该 区域中的数据在 ...
- 修改Linux的SSH远程连接端口 技巧
将SSH终端服务的端口由 22 修改为别的端口以防攻击黑客直接猜解您的服务器密码 首先修改配置文件 vi /etc/ssh/sshd_config 找到 #Port 22 一段,这里是标识默认使用 2 ...
- 1·3 对 git 的认识
我可以诚实的说:这是我第一次听见这个名词 GIT.老师您发的关于git链接我下载了,只是还没看完.所以以下只是片面的理解,在后期我会单独再发一次. 一·GIT的简单介绍 1·Git是一款免费.开源的分 ...
- spark streaming 接收 kafka 数据java代码WordCount示例
http://www.cnblogs.com/gaopeng527/p/4959633.html
- $.prop()和$.attr() 区别用法
都用于读取和设置DOM元素节点的属性 不同: $.attr()用于DOM元素本身的属性 $.prop()用于DOM节点对应的JS属性(源于DOM元素到JS对象的映射) 源于两者在jquery类库的实现 ...
- jquery写简单的div切换
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- win7无法保存打印机设置(错误0x000006d9)解决方法
解决win7打印机共享出现‘无法保存打印机设置’操作无法完成(错误0x000006d9),接下来与大家分享下解决方法, 找到windows firewall服务,启用即可 ============== ...
- VC++ 应用程序无法正常启动0xc0150002
使用VC++开发软件,编译后的程序打不开,弹出错误框: 使用Dpends Walker查看依赖项,没有什么异常. 然后,右键"计算机",选择"管理",打开计 ...
- MySQL找回管理员密码
更改MySQL提示符 mysql> prompt \u@mysql \r:\b:\s 查找以my开头的数据库 mysql> show databases like 'my%' 删除用户所有 ...