Codeforces Round #210
A:简单题:
#include<cstdio>
using namespace std; int n,k;
int main()
{
scanf("%d%d",&n,&k);
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
if(i==j)printf("%d ",k);
else printf("0 ");
}
puts("");
}
return ;
}
B.简单题:
#include<cstdio>
using namespace std; int n,k;
int main()
{
scanf("%d%d",&n,&k);
if((n==&&k==)||k==n)
{
puts("-1");
return ;
}
if(k==)
{
for(int i=;i<n;i++)
printf("%d ",i+);
puts("");
return ;
}
if(k==n-)
{
for(int i=;i<=n;i++)
printf("%d ",i);
return ;
}
printf("%d ",k+);
for(int i=; i<=k+; i++)
{
printf("%d ",i);
}
for(int i=k+; i<n; i++)
printf("%d ",i+);
printf("");
return ;
}
C:暴力,先从后往前搞一遍,然后从前往后检查一遍;
#include<cstdio>
#include<algorithm>
#define maxn 5005
using namespace std; int p[maxn],ans[maxn];
int cmd[maxn],l[maxn],r[maxn],num[maxn];
bool vis[maxn],flag;
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<m;i++)scanf("%d%d%d%d",&cmd[i],&l[i],&r[i],&num[i]);
for(int i=;i<=n;i++)p[i]=-;
for(int i=m-;i>=;i--)
{
if(cmd[i]==)
{
for(int j=l[i];j<=r[i];j++)
p[j]-=num[i];
}
else
{
for(int j=l[i];j<=r[i];j++)
{
if(vis[j]&&p[j]<=num[i])continue;
p[j]=num[i];
vis[j]=;
}
}
}
for(int i=;i<=n;i++)ans[i]=p[i];
for(int i=;i<m;i++)
{
if(cmd[i]==)
{
for(int j=l[i];j<=r[i];j++)
p[j]+=num[i];
}
else
{
int ma=-;
for(int j=l[i];j<=r[i];j++)
ma=max(ma,p[j]);
if(ma!=num[i]){flag=;break;}
}
}
if(flag)puts("NO");
else
{
puts("YES");
for(int i=;i<=n;i++)
printf("%d ",ans[i]);
}
return ;
}
D:二分+dp: |ai-aj|<=(j-i)*x
#include <cstdio>
#include <algorithm>
#define MAXN 2005
#define LL long long
using namespace std;
int a[MAXN] , b[MAXN] , sum , k ,n;
bool ok(int d)
{
for(int i = ; i<= n; i++)
b[i] = ;
for(int i = ; i <= n ; i++)
{
for(int j = ; j < i ; j++)
{
if(abs(a[i] - a[j]) <= (LL)(i - j) * d)
b[i] = max(b[i] , b[j] + );
}
}
sum = ;
for(int i = ; i <= n ; i++)sum = max(sum , b[i]);
return n - sum <= k;
}
int main()
{
int l = , r = *;
scanf("%d%d" , &n , &k);
for(int i = ; i <= n ; i++)scanf("%d" , &a[i]);
while(l <= r)
{
int Mid = ((LL)l + r) / ;
if(ok(Mid))r = Mid - ;
else l = Mid + ;
}
printf("%d\n" , l);
return ;
}
Codeforces Round #210的更多相关文章
- Codeforces Round #210 (Div. 2) A. Levko and Table
让对角线的元素为k就行 #include <iostream> using namespace std; int main() { int n,k; cin >> n > ...
- Codeforces Round #210 (Div. 2) C. Levko and Array Recovery
题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...
- CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发 问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候 如果对于一条边 ...
- Codeforces Round #210 (Div. 1).B
经典的一道DP题. 题目明显是一道DP题,但是比赛的时候一个劲就在想怎么记录状态和转移.最后想到了一种n^3的方法,写了下,不出所料的超时了. 看了别人的代码才发现竟然是先二分然后再进行DP,像这种思 ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3)(A.B.C,3道暴力题,C可二分求解)
A. Is it rated? time limit per test:2 seconds memory limit per test:256 megabytes input:standard inp ...
- Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心
A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #412 Div. 2 第一场翻水水
大半夜呆在机房做题,我只感觉智商严重下降,今天我脑子可能不太正常 A. Is it rated? time limit per test 2 seconds memory limit per test ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- ADC及DA的头文件复析
/************************************************************* ADC12,,,,这么多的定义,搞得我都昏死啦,抽出来可能好几一些..** ...
- systemverilog interface
普通的模块使用法:注意我们这里只实现了部分功能....不是完全的读写模块.... module mem_core( input logic wen, input logic ren, ...
- CCLablettf读取显示xml文件内容显示中文
CCDictionary *strings = CCDictionary::createWithContentsOfFile("tips2.xml"); const char *h ...
- box-shadow学习笔记
CSS3 box-shadow属性的简单学习笔记 语法格式: box-shadow: h-shadow v-shadow blur spread color inset; 值 描述 h-shadow ...
- Android之Http网络编程(一)
Android应用作为一个客户端程序绝大部分都是需要进行网络请求和访问的,而http通信是一种比较常见并常用的通信方式. 在Android中http网络编程中有两种实现方式,一种是使用HttpURLC ...
- SQL 分组后取最小行号记录
本示例测试两个表联接查询后,分组并取分组后的最小行号记录 测试表: tb1表结构如下: CREATE TABLE [dbo].[tb1]( ) NOT NULL, ) NULL, ) NULL, CO ...
- SQL Server调优系列进阶篇 - 如何重建数据库索引
随着数据的数据量的急剧增加,数据库的性能也会明显的有些缓慢这个时候你可以考虑下重建索引或是重新组织索引了. DBCC SHOWCONTIG('表名') 可以查看当前表的索引碎情况. 重建索引 方法一: ...
- 再探Linux动态链接 -- 关于动态库的基础知识
在近一段时间里,由于多次参与相关专业软件Linux运行环境建设,深感有必要将这些知识理一理,供往后参考. 编译时和运行时 纵观程序编译整个过程,细分可分为编译(Compiling,指的是语言到平台 ...
- Android Metro风格的Launcher开发系列第一篇
前言:从毕业到现在已经三年多了,回忆一下这三年基本上没有写过博客,总是觉得忙,没时间写,也觉得写博客没什么大用.但是看到很多大牛们都在写博客,分享自己的东西,所以嘛本着向大牛看齐,分享第一,记录第二的 ...
- ubuntu tab命令补全失效
主要是由于环境变量设置出了问题,修改/etc/environment即可. sudo nano /etc/environment 修改后source /etc/environment