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. INSTALLING QUARTUS II V.13.1 64 BIT ON RHEL/CENTOS 6 64 BIT

    http://www.digitalsolutionslab.com/installing-quartus-ii-v-13-1-64-bit-on-rhelcentos-6-64-bit/ I hav ...

  2. Centos 7中 vim 中文乱码

    参考:http://www.myexception.cn/operating-system/1534005.html 一. sudo vim /etc/vimrc 在文件中加入如下几行:      s ...

  3. HttpWebRequest 上传图片

    public string HttpUploadFile() { string url = "http://localhost:50380/WebForm1.aspx"; stri ...

  4. spring beans的写入工具——spring-beans-writer

    spring-beans-writer是我曾经为动态生成spring beans配置文件做的一个写入工具,托管地址: https://github.com/bluejoe2008/spring-bea ...

  5. Asp.Net Cookie的清除

    背景 最近做到一个asp.net项目,项目中保存用户信息用到了cookie,因此,在注销身份的时候,就需要清除掉cookie. 探索过程 我先是试验了这种代码,在没有特殊声明前,代码都是写在Page_ ...

  6. Docker Machine, Compose, and Swarm: How They Work Together

    The three tools are now neatly packaged into what’s called the Docker Toolbox. Docker Machine1/ crea ...

  7. Java中的String类

    /*String类用于描述字符串事物的那么它就提供了多个方法对字符串进行操作 方法都会用,字符串这块就结束了常见的操作有哪些?“abcd”它应该具备什么功能,我们才能更好得操作它?1.获取(必须要掌握 ...

  8. Java多线程--同步函数

    /*需求:银行有一个金库有两个储户分别存300元 每次存100元,存3次 目的:该程序是否有安全问题,如果有,如何解决? 如何找问题(很重要)1.明确哪些代码是多线程运行代码2.明确共享数据3.明确多 ...

  9. GNU glibc

    在线G-lib-c(GNU C Library库)网站 参考: 1.bitsToTypes

  10. 禁用Linux bash rm --force

    防止无意的Linux bash rm --force 二.禁用rm -rf 因为rm -rf 删除文件的时候,经常会不小心将系统文件或者多个有用的目录删除掉.有两种方法:1,每次删除都用-i(inte ...