A,B,C都是水题。。。

D题,直接爆搜。我换了好多姿势,其实最简单的方法,就能过。

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
int que[];
int p[];
int o[];
int temp[];
int st[];
int ans,minz;
int n,a,b;
void dfs(int x,int sum)
{
int i;
if(sum >= minz) return;
if(x == n)
{
for(i = ;i <= n;i ++)
temp[i] = p[i];
for(i = ;i <= n-;i ++)
{
temp[i] -= o[i]*a;
temp[i-] -= o[i]*b;
temp[i+] -= o[i]*b;
}
for(i = ;i <= n-;i ++)
{
if(temp[i] >= ) break;
}
if(i == n)
{
if(sum < minz)
{
minz = sum;
for(i = ;i <= n-;i ++)
st[i] = o[i];
}
}
return ;
}
for(i = ;i <= ;i ++)
{
o[x] = i;
dfs(x+,sum+i);
}
}
int main()
{
int i,j;
scanf("%d%d%d",&n,&a,&b);
for(i = ; i <= n; i ++)
{
scanf("%d",&p[i]);
}
while(p[] >= )
{
que[ans++] = ;
p[] -= b;
p[] -= a;
p[] -= b;
}
while(p[n] >= )
{
que[ans++] = n-;
p[n-] -= b;
p[n] -= b;
p[n-] -= a;
}
for(i = ;i <= n;i ++)
{
if(p[i] >= ) break;
}
if(i == n+)
{
printf("%d\n",ans);
for(i = ;i < ans;i ++)
printf("%d ",que[i]);
printf("\n");
return ;
}
minz = ;
dfs(,);
printf("%d\n",minz+ans);
for(i = ;i < ans;i ++)
printf("%d ",que[i]);
for(i = ;i <= n-;i ++)
{
for(j = ;j <= st[i];j ++)
printf("%d ",i);
}
printf("\n");
return ;
}

E题,二分+rmq之类的,能求区间最值的算法。

题意是比较扯,按章节排列的n本书,要展示,最长能展示多少本,这一段的高度差要小于等于k,再输出总共多少中情况,把起点,终点输出。

rmq好久没写过了啊,记不得 什么东西了。

#include <cstdio>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
int n,k;
int p[];
int dpmin[][];
int dpmax[][];
int bin[];
void CL(int n)
{
int i,j;
for(i = ;i <= n;i ++)
{
dpmin[][i] = p[i];
dpmax[][i] = p[i];
}
for(i = ;bin[i] <= n;i ++)
{
for(j = ;j + bin[i-] <= n;j ++)
{
dpmin[i][j] = min(dpmin[i-][j],dpmin[i-][j+bin[i-]]);
dpmax[i][j] = max(dpmax[i-][j],dpmax[i-][j+bin[i-]]);
}
}
}
int rmqmax(int s,int t)
{
int k = log((t-s+)*1.0)/log(2.0);
return max(dpmax[k][s],dpmax[k][t-bin[k]+]);
}
int rmqmin(int s,int t)
{
int k = log((t-s+)*1.0)/log(2.0);
return min(dpmin[k][s],dpmin[k][t-bin[k]+]);
}
int query(int s,int t)
{
return rmqmax(s,t) - rmqmin(s,t);
}
int judge(int mid)
{
int i,ans = ;
for(i = ;i <= n-mid+;i ++)
{
if(query(i,i+mid-) <= k)
ans ++;
}
return ans;
}
int main()
{
int i,j,str,end,mid;
scanf("%d%d",&n,&k);
for(i = ;i <= n;i ++)
scanf("%d",&p[i]);
bin[] = ;
for(i = ;i <= ;i ++)
bin[i] = bin[i-]*;
CL(n);
str = ;
end = n;
while(str < end)
{
mid = (str + end + )/;
if(judge(mid))
str = mid;
else
end = mid - ;
}
printf("%d %d\n",end,judge(end));
for(i = ;i <= n-end+;i ++)
{
if(query(i,i+end-) <= k)
{
printf("%d %d\n",i,i+end-);
}
}
return ;
}

Codeforces Beta Round #6 (Div. 2 Only)的更多相关文章

  1. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  2. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  3. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  4. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  5. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  7. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  8. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

  9. Codeforces Beta Round #72 (Div. 2 Only)

    Codeforces Beta Round #72 (Div. 2 Only) http://codeforces.com/contest/84 A #include<bits/stdc++.h ...

  10. Codeforces Beta Round #70 (Div. 2)

    Codeforces Beta Round #70 (Div. 2) http://codeforces.com/contest/78 A #include<bits/stdc++.h> ...

随机推荐

  1. C# 中的Singleton模式

    一般写Singleton基本都是一下这个套路 class Singleton { public static Singleton instance; private Singleton() { } p ...

  2. C# virtual override 和 new 的区别

    一直以来我都对 virtual  override 和 new 之间的区别感到疑惑不解. 特别笔试的时候特别容易考到,真的很容易弄错啊,畜生! 光看理论永远记不住,那不如写几行代码就懂了. 首先看看v ...

  3. 无废话ExtJs 入门教程十[单选组:RadioGroup、复选组:CheckBoxGroup]

    无废话ExtJs 入门教程十[单选组:RadioGroup.复选组:CheckBoxGroup] extjs技术交流,欢迎加群(201926085) 继上一节内容,我们在表单里加了个一个单选组,一个复 ...

  4. java compiler level does not match the version of the installed java project

    修改:工程/.settings/”目录下找到名为 org.eclipse.wst.common.project.facet.core.xml

  5. <转>SQL语句执行顺序说明

    原文地址:http://www.cnblogs.com/summer_adai/archive/2011/10/28/2227605.html SQL 不同于与其他编程语言的最明显特征是处理代码的顺序 ...

  6. 如何安装sublime text2以及它的插件?

    下载Sublime Text2的安装包,安装,安装后打开的界面如图   下面我们来给他安装插件,首先安装packagecontrol,打开菜单栏中的View-->show console   在 ...

  7. iOS开发资料链接

    ios开发中文文档了 http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/RoadMapiOSCh/chap ...

  8. js jquery 实现点击按钮后,倒计时60秒才能再次点击发送验证邮件

    <input type="button" id="btn" value="免费获取验证码" /><script type= ...

  9. JMeter中的关联-正则表达式提取(1)

    运用Jmeter正则提取器,可以从请求的响应结果中取到需要的内容,从而实现关联. jmeter之关联 的个人理解: 关联是请求与请求之间存在数据依赖关系,需要从上一个请求获取下一个请求需要回传回去的数 ...

  10. lr_think_time参数化

    深圳湖北籍软件测试群 275212937