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. Python(2.7.6) copy - 浅拷贝与深拷贝

    Python 标准库的 copy 模块提供了对象拷贝的功能. copy 模块中有两个函数 copy 和 deepcopy,分别支持浅拷贝与深拷贝. copy_demo.py import copy c ...

  2. SpringMVC使用@ResponseBody注解返回中文字符串乱码的问题

    先说一下我的经历,以及解决问题的而过程. 在使用SpringMVC的时候,最开始的时候在配置文件中使用<mvc:annotation-driven />去自动注册DefaultAnnota ...

  3. angularjs开发总结

    使用AngularJS有差不多一年时间了,前前后后也用了不少库和指令,整理了一下,分成四大类列出.有demo地址的,就直接连接到demo地址,其它的直接链到github托管库中. 图片视频类 angu ...

  4. WCF编程系列(四)配置文件

    WCF编程系列(四)配置文件   .NET应用程序的配置文件 前述示例中Host项目中的App.config以及Client项目中的App.config称为应用程序配置文件,通过该文件配置可控制程序的 ...

  5. 第十篇、HTML5实战篇——1

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <!--支持IE ...

  6. 不显示UITableView底部多余的分割线

    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

  7. Xcode中添加代码块的方式

    在写代码的过程中,经常会有重复的代码(比如说,cell的使用),当然了复制粘贴也不是不行,但是Xcode提供了一个很方便的东西. 1.在Xcode右下角你会看到有一个{}的东西,这里是一些常用的代码块 ...

  8. 帝国CMS附件大小限制

    做文件的上传下载,在我们本地测试总是顺利通过,一上传到服务器各种问题都来了. 帝国CMS,我们先看网站配制中附件大小限制. 附件存放目录设置: 单击菜单“系统”>“系统设置”>“系统参数设 ...

  9. [算法] get_lucky_price price

    int get_lucky_price(int price, const vector & number) 题意大概是给你一个数price,比如1000,然后有unlucky_num,有{1, ...

  10. (转)MySQL Workbench的使用教程 (初级入门版)

    转自:http://www.cnblogs.com/yqskj/archive/2013/03/01/2938027.html MySQL Workbench 是 MySQL AB 最近释放的可视数据 ...