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的更多相关文章

  1. Codeforces Round #210 (Div. 2) A. Levko and Table

    让对角线的元素为k就行 #include <iostream> using namespace std; int main() { int n,k; cin >> n > ...

  2. Codeforces Round #210 (Div. 2) C. Levko and Array Recovery

    题目链接 线段树的逆过程,想了老一会,然后发现应该是包含区间对存在有影响,就不知怎么做了...然后尚大神,说,So easy,你要倒着来,然后再正着来,判断是不是合法就行了.然后我乱写了写,就过了.数 ...

  3. CodeForces 360E Levko and Game(Codeforces Round #210 (Div. 1))

    题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候  如果对于一条边 ...

  4. Codeforces Round #210 (Div. 1).B

    经典的一道DP题. 题目明显是一道DP题,但是比赛的时候一个劲就在想怎么记录状态和转移.最后想到了一种n^3的方法,写了下,不出所料的超时了. 看了别人的代码才发现竟然是先二分然后再进行DP,像这种思 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #412 Div. 2 第一场翻水水

    大半夜呆在机房做题,我只感觉智商严重下降,今天我脑子可能不太正常 A. Is it rated? time limit per test 2 seconds memory limit per test ...

  8. 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 ...

  9. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

随机推荐

  1. matlab中num2str的应用

    在求导数,积分,方程的过程中,难免会遇到一些参数要随着情况有点变化,这时,你就需要能够动态的表示出你的表达式,Num2str函数是一个相当有用的函数,一般配合[]连接符使用,下面将我接触到的一些用法写 ...

  2. nodejs使用express4框架默认app.js配置说明

    var express = require('express'); //引入express模块 var path = require('path'); //引入path模块,该模块包括了一些处理文件路 ...

  3. js数组求和

    array1.reduce(callbackfn[, initialValue]) callback : 函数执行在数组中每个值 initialValue : 对象作为第一个参数回调的第一次调用使用 ...

  4. 在安卓下使用python连接蓝牙串口模块(HC-06)

    在安卓上安装Python: 请参考:https://github.com/kuri65536/python-for-android/blob/master/README.md下载程序文件需要访问 ht ...

  5. Android -tool工具UIautomatorviewer提示“不能让屏幕黑屏”

    Android中有很多工具可以让我们使用,我使用比较多的有属DDMS,UIautomatorviewer,DDMS中信息也很强大,有空的时候在理理 这篇博主写的很详细:http://www.cnblo ...

  6. 阿里云 mysql 无缘无故挂掉

    近期在登录自己博客时,老是报数据库连接失败,然后重启服务器就好了.但是,重启服务器很耗时间,不方便,不能每次都重启吧于是远程连接服务器看了一下原来是数据库服务挂掉了启动时还报错于是查看了下错误日志 2 ...

  7. Masonry 控件详解

    1.   Masonry的属性 @property (nonatomic,strong,readonly)MASConstraint *left; //左侧 @property(nonatomic,s ...

  8. iOS 9 适配需要注意的问题

    iOS 9 适配需要注意的问题 1`网络适配_改用更安全的HTTPS iOS9把所有的http请求都改为https了:iOS9系统发送的网络请求将统一使用TLS 1.2 SSL.采用TLS 1.2 协 ...

  9. mysql空间数据相关操作

    建表语句: CREATE TABLE ts.points ( name ) NOT NULL, location POINT NOT NULL, description ) ); 添加记录如下: IN ...

  10. 杂技之sharpdevelop调试aps.net

    背景: 本人笔记本电脑不给力,vs打开实在太慢,因此考虑使用sharpdevelop,但sharpdevelop有点麻烦事,就是不支持asp.net的调试,为解决此问题,本人在此杂技一把了 方案一: ...