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 ...
随机推荐
- 关于Git远程版本库
Git作为分布式版本库控制系统,每个人都是本地版本库的主人,可以在本地的版本库中随心所欲的创建分支和里程碑. 当需要多人协作时,问题就出现了: 1.如何避免因为用户把所有的本地分支都推送到了共享版本库 ...
- Ubuntu 安装php_intl 扩展
PHP Intl 类在I18n的网站中真的很方便,允许你依赖在终端用户区域,很容易的输出正确的日期格式. 在使用 yii2-app-ecom , 初始化之后,访问首页出现了: The default ...
- Linux 查看文件修改
在以前知道在Linux下查看Tomcat日志文件, tail -f catalina.out 同样的命令"tail -f filename",我就可以看其它日志文件啦: tail ...
- JavaScript - Base64 编码解码
以下代码摘自:http://cryptojs.altervista.org/encoding/Base64.html function base64_encode(str) { if (window. ...
- .net MVC中JsonResult 返回类
/// <summary> /// 返回消息类 /// </summary> public class ReturnMessage { private IDictionary& ...
- .NET 进程和线程
一.进程:需要有用Process类用法一:Process.Start("calc");该方法弊端:有许多程序不知道它的运行名字到底是什么,如果写错了,就会出现程序崩溃错误用法二:/ ...
- WPF 中,动态创建Button,并使Button得样式按照自定义的Resource样式显示
第一步:自定义一个Button的样式 1.新建一个xaml文件,在其中自定义好自己的Resources 这个Resource 的根节点是 <ResourceDictionary xmlns=&q ...
- 关于insertBefore
insertBefore,看名字就是在某个元素前插入元素,但是其实它可以再文档任何元素强势插入. insertBefore用法: parent.insertBefore(newChild, refCh ...
- [PS] 透明底图片制作
网页中有时需要自己绘制一些图片,或者现有的图片希望修改底色,这些都会用到透明底色的图片,下面总结两种方法,比较简单入门. 一.自己制作透明底图片 步骤1.新建图片,背景内容选择透明: 步骤2.选择文字 ...
- 记个maven无法识别JAVA_HOME的问题 Error: JAVA_HOME is not defined correctly.
Error: JAVA_HOME is not defined correctly. We cannot execute /Library/Java/JavaVirtualMachines/jdk1. ...