Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】
呵呵哒,上分~
CodeForces 724A:
题意:
给你两个星期几,问连续两个月的头一天是否满足;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; typedef long long LL;
char s1[20],s2[20];
char s[7][11]= {"monday","tuesday","wednesday","thursday","friday","saturday","sunday"};
int n,m; void solve()
{
for(int i=0;i<7;i++)
{
if(strcmp(s1,s[i])==0)
n=i+1;
if(strcmp(s2,s[i])==0)
m=i+1;
}
}
void judge()
{
if(n>m)
m+=7;
m-=n;
if(m==0||m==2||m==3)
printf("YES\n");
else
printf("NO\n");
} int main()
{
scanf("%s%s",s1,s2);
solve();
judge();
return 0;
}
CodeForces 724B:
题意:
给你一个二维数组,每一行可以不超过一次移动,还可以不超过一次进行任意两列互换;
思路:
状压枚举两列互换的情况,然后对每一行判断,注意还要判断列没有换的情况(我也不知道需不需要,不过判了,没有wa,应该是需要的)
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; typedef long long LL; int a[25][25];
int tmp1[25];
int tmp2[25];
int n,m; bool Judge(int i,int x)
{
int f1=-1;
int f2=-1;
for(int j=0;j<m;j++)
{
if(x&(1<<j))
{
if(f1==-1)
f1=j;
else
f2=j;
}
}
tmp2[f1]=tmp1[f1]=a[i][f2];
tmp2[f2]=tmp1[f2]=a[i][f1];
for(int j=0;j<m;j++)
if(j!=f1&&j!=f2)
tmp2[j]=tmp1[j]=a[i][j];
sort(tmp1,tmp1+m);
int cnt=0;
for(int j=0;j<m;j++)
if(tmp1[j]!=tmp2[j])
{
cnt++;
if(cnt>2)
return false;
}
return true;
} bool judge_hang(int temp)
{
for(int i=0;i<n;i++)
{
if(!Judge(i,temp))
return false;
}
return true;
} int main()
{
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&a[i][j]); int N=1<<m;
for(int i=0;i<N;i++)
{
int cnt=0;
for(int j=0;j<m;j++)
{
if(i&(1<<j)) cnt++;
}
if(cnt==2||!i)
{
if(judge_hang(i))
{
puts("YES");
return 0;
}
}
}
puts("NO");
return 0;
}
CodeForces 724C:
题意:
射线从(0,0)往(1,1)方向,碰到墙反射,到四个角结束,给你n,m,k,n*m长宽,k点个个数,对于给出点,求最短到达时间,如果不能到达输出"-1"
思路:
暴力处理反弹有多少线,然后处理线上的点,可以预处理输入点的那些经过的线;
CodeForces 724D:
题意:
思路:
我们先考虑几个小问题:
我说在某个m个区间里,我找到了一个最小的,那我取它,行不行,比如m=3 对某个区间是abb,我取a,非常同情达理啊,那我换一下,这个区间是aaa的时候,我是取第一个a还是取第3个a,还是都取,其实这个时候问题就出来了,我们说对于一个答案串,aabbb,然后但是这里有3个aaa是吧,那我肯定得把a全取了啊,这样就能顶替b了,从而达到了字典序最小的字符串,但是如果我说,这个答案串是:aaaaaa那么对于这个区间来说(保证要取),那一定是只取一个就够了,多取只会增大字典序。
那么从而达到一个贪心策略:
对于一个[ i,i+m-1 ]这个区间必取,我们可以维护一个已取的最大值MAX,如果这个区间一有比MAX小的就直接拿过来,因为比最大的小啊,在一定程度上就可以把最大的顶开啊,比如现在已经找到aacc,那我已找到b,就拿过来aabcc,所以一定可以使大的元素的位置远离首位达到字典序变小,然后如果都是>=b呢?那么就取一个最远的,因为还是越少越好啊~
所以总的方案简略的说就是,先顶了最大,如果>=最大,那么就是最小的最远;
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
#define mod 10007
#define INF 0x3f3f3f
const double pi=acos(-1.0);
typedef long long LL;
const int MAX=100010;
int n,m;
char s[MAX];
int v[MAX];
int num[110];
int main()
{
int i,j,t,k;
scanf("%d%s",&m,s);
memset(v,0,sizeof(v));
memset(num,0,sizeof(num));
n=strlen(s);
if(n<=m)
{
char x='z';
for(i=0; i<n; i++)
{
if(s[i]<x)
x=s[i];
}
printf("%c\n",x);
return 0;
}
int l=0;
char b='a';
for(i=0; i<n&&i<n-m+1; i++)
{
k=0;
char a='z';
for(j=i; j<m+i; j++)
{
if(s[j]<b)
{
k=j;
break;
}
if(s[j]<=a)
{
a=s[j];
k=j;
}
}
if(s[k]>b)
b=s[k];
num[s[k]-'a']++;
v[k]=1;
i=k;
// printf("%d\n",k);
}
for(i=0; i<n; i++)
{
if(s[i]<b&&!v[i])
{
num[s[i]-'a']++;
}
}
for(i=0; i<26; i++)
{
while(num[i])
{
char x=i+'a';
printf("%c",x);
num[i]--;
}
}
return 0;
}
Intel Code Challenge Final Round (Div. 1 + Div. 2, Combined)【A,B,C,D】的更多相关文章
- 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) 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 ...
随机推荐
- spring boot Mybatis多数据源配置
关于 有时候,随着业务的发展,项目关联的数据来源会变得越来越复杂,使用的数据库会比较分散,这个时候就会采用多数据源的方式来获取数据.另外,多数据源也有其他好处,例如分布式数据库的读写分离,集成多种数据 ...
- lnmp下 nginx 配置虚拟主机
<一.参考> 这里以配置2个站点(2个域名)为例,n 个站点可以相应增加调整,假设: IP地址: 202.55.1.100 域名1 example1.com 放在 /www/example ...
- jquery live hover
$("table tr").live({ mouseenter: function() { //todo }, mouseleave: function() { //todo } ...
- objective-c中#import和@class的差别
在Objective-C中,能够使用#import和@class来引用别的类型, 可是你知道两者有什么差别吗? @class叫做forward-class, 你常常会在头文件的定义中看到通过@cla ...
- etymology-I
1)inter-.intra-.intro- 三个前缀inter-,intra-和intro-还是有差别的. inter-表between,如international那是between differ ...
- 话题讨论&征文--谈论大数据时我们在谈什么 获奖名单发布
从社会发展趋势的角度,非常明显大数据会是眼下肉眼可及的视野范围里能看到的最大趋势之中的一个.从传统IT 业到互联网.互联网到移动互联网,从以智能手机和Pad 为主要终端载体的移动互联网到可穿戴设备的移 ...
- html5 file 上传图片
说明:开发环境 vs2012 mvc4项目,后台语言csharp 1.前端代码 <html xmlns="http://www.w3.org/1999/xhtml"> ...
- linux socket详解
1 linux socket编程的固定模式 server端,bind.listen.accept client端,connect client端和server端之间的一次通信: client端,wri ...
- mybatis入门(五)
根据用户名称模糊查询用户信息 @Test public void findUserByNameTest() throws IOException { // 通过工厂得到SqlSession SqlSe ...
- 最简单的基于FFMPEG的Helloworld程序
===================================================== 最简单的基于FFmpeg的视频播放器系列文章列表: 100行代码实现最简单的基于FFMPEG ...