http://codeforces.com/contest/737

A:

题目大意: 有n辆车,每辆车有一个价钱ci和油箱容量vi.在x轴上,起点为0,终点为s,中途有k个加油站,坐标分别是pi,到每个加油站都可以加满油。 每辆车有2种模式,加速模式花1分钟和2个单位的油前进1个单位,正常模式花2分钟和1个单位的油前进1个单位。  要求选一辆最便宜的车,使得开这辆车从起点到终点的时间小于等于t.从起点出发的时候油是满的。

n,k<=105.  vi,pi,s<=109

思路:

首先由于每次都可以加满油,可以对每一段路分开考虑。 假设某一段长度为len个单位,设有x个单位的路是用加速模式的,那么耗时t=x+2*(len-x)=2*len-x ;

显然x越大t越小。    但是还要满足2个条件: x<=len ,  耗油量 2x+(len-x)=x+len<=v.   要把这两个条件合并起来,只要分两类讨论。

当len<=0.5v的时候,  x<=len;     当x=len的时候t取最小值len;

当len>  0.5v的时候,  x<=v-len;  当x=v-len的时候t取最小值3*len-v;

所以只要把所有的len按长度排个序,  枚举车辆i, len<=0.5vi的可以一起算, len>0.5vi的一起算。 二分一下分界点就好。 时间复杂度O(nlogn).

代码:

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
using namespace std; #define X first
#define Y second
#define Mod 1000000007
#define N 200010
typedef long long ll;
typedef pair<int,int> pii; inline int Mul(int x,int y){return 1ll*x*y%Mod;}
inline int Add(int x,int y){return ((x+y)%Mod+Mod)%Mod;} int n,s,t,k,r;
int p[N],c[N],v[N],b[N];
ll sum[N]; int main()
{
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout); scanf("%d%d%d%d",&n,&k,&s,&t);
for (int i=;i<=n;i++) scanf("%d%d",&c[i],&v[i]);
for (int i=;i<=k;i++) scanf("%d",&p[i]);
sort(p+,p+k+);
int maxlen=;
for (int i=;i<=k;i++) maxlen=max(maxlen,p[i]-p[i-]),b[r++]=p[i]-p[i-];
maxlen=max(maxlen,s-p[k]); b[r++]=s-p[k];
sort(b,b+r);
sum[]=b[];
for (int i=;i<r;i++) sum[i]=b[i]+sum[i-];
int ans=2e9; for (int i=;i<=n;i++)
{
if (v[i]-maxlen<) continue; int pos=lower_bound(b,b+r,v[i]*0.5)-b; if (pos==r || *b[pos]>v[i]) pos--;
ll tmp=sum[pos]+*(sum[r-]-sum[pos])-1ll*v[i]*(r-pos-);
if (tmp<=t && ans>c[i]) ans=c[i]; }
if (ans==2e9) ans=-;
printf("%d\n",ans); return ;
}

B:

题目大意:  有n个位置排成一排,在上面放了a个长度为b的互不相交的方块。选一些格子射击,一开始已经射了k次(给了一个01字符串1表示被射过),但是都没射中任何一个方块。现在要再选最少的格子射击,使得不管怎么摆这些方块,至少有一个方块被射到。           n<=105

思路:

1.假设我们选好了一些位置来射击,把射击的位置标记为1,如果不管怎么摆这些方块,至少有一个方块被射到 等价于只在0的位置上放方块,最多能放的方块数<a.

2.对于某一块连续的0,假设长度为len,那么这一段最多能放$\frac{len}{b}$ 个方块。 因此如果我们让len减少b,能放的方块就少了一个。所以这样构造:在连续的0上每隔b个单位就射击一次,这样每射击一次能放得方块数就减少1,直到减少到a-1.  显然这样射击的次数是最少的。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
using namespace std; #define X first
#define Y second
#define Mod 1000000007
#define N 200010
typedef long long ll;
typedef pair<int,int> pii; int n,a,b,k,t;
int l[N],r[N],len[N],ans[N];
char s[N]; inline int f(int x){return x/b;} int main()
{
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout); scanf("%d%d%d%d",&n,&a,&b,&k);
scanf("%s",s+); s[n+]='';
for (int i=,pre=;i<=n+;i++)
{
if (s[i]=='')
{
t++;
l[t]=pre+;
r[t]=i-;
len[t]=i-pre-;
pre=i;
}
} int sum=;
for (int i=;i<=t;i++) sum+=f(len[i]); for (int i=;i<=t;i++)
{
int x=l[i]+b-;
while (x<=r[i] && sum>=a) ans[++ans[]]=x,x+=b,sum--;
}
printf("%d\n",ans[]);
for (int i=;i<=ans[];i++) printf("%d%c",ans[i],i==ans[]? '\n':' '); return ;
}

C:

题目大意:有n个点,以s为根构成一棵树,  每个点有ai个祖先(包括父亲), 要求修改最少的ai,使得存在这样的一棵树。

思路:

1. ai其实就是节点的深度。 可以发现,假设一棵树最大深度是maxdep,那么肯定存在深度为0,1,2...maxdep的节点,也就是说深度是连续的。

2. 节点s的ai必须是0. 如果不是,必须把它修改成0. 之后就可以不管s了。

3. 考虑枚举最大深度, 先统计一下c[k],表示ai=k的个数。 假设现在枚举到最大深度为d, 深度0-d中有cnt个不存在,  ai>d的这些点肯定是需要修改的,既然要修改,不如把它用来填补那cnt个空位。 另外ai=0的点肯定也是要修改的。  具体实现看代码。

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdlib>
#include <set>
#include <queue>
using namespace std; #define X first
#define Y second
#define Mod 1000000007
#define N 200110
#define M 200110
typedef long long ll;
typedef pair<int,int> pii; int n,s,ans,t;
int a[N],c[N],sum[N]; int main()
{
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout); int cnt=; ans=1e9;
scanf("%d%d",&n,&s);
for (int i=;i<=n;i++) scanf("%d",&a[i]);
if (a[s]!=) t=; a[s]=n+;
if (n==) {printf("%d\n",t); return ;}
for (int i=;i<=n;i++) c[a[i]]++;
for (int i=n-;i>=;i--) sum[i]=sum[i+]+c[i]; for (int i=;i<n;i++)
{
if (!c[i]) cnt++;
if (sum[i+]+c[]>=cnt) ans=min(ans,sum[i+]+c[]);
else ans=min(ans,cnt);
}
printf("%d\n",ans+t); return ;
}

比赛的时候只会ABC, 争取近几天把后面的题补上。

Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)的更多相关文章

  1. codeforces Codeforces Round #380 (Div. 1, Rated, Based on Technocup 2017 - Elimination Round 2)// 二分的题目硬生生想出来ON的算法

    A. Road to Cinema 很明显满足二分性质的题目. 题意:某人在起点处,到终点的距离为s. 汽车租赁公司提供n中车型,每种车型有属性ci(租车费用),vi(油箱容量). 车子有两种前进方式 ...

  2. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) E. Subordinates 贪心

    E. Subordinates time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  3. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2) D. Sea Battle 模拟

    D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  4. Codeforces Round #380 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 2)C. Road to Cinema 二分

    C. Road to Cinema time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  5. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) C

    Description Santa Claus has Robot which lives on the infinite grid and can move along its lines. He ...

  6. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) B

    Description Santa Claus decided to disassemble his keyboard to clean it. After he returned all the k ...

  7. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) A

    Description Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the f ...

  8. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) D. Santa Claus and a Palindrome STL

    D. Santa Claus and a Palindrome time limit per test 2 seconds memory limit per test 256 megabytes in ...

  9. Codeforces Round #389 (Div. 2, Rated, Based on Technocup 2017 - Elimination Round 3) E. Santa Claus and Tangerines

    E. Santa Claus and Tangerines time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. sql 连接查询的区别 inner,left,right,full

    --table1 表 ID NAME QQ PHONE1 秦云 10102800 135000002 在路上 10378 136000003 LEO 10000 139000004 秦云 024145 ...

  2. PHP入门【一】$_SERVER

    这几天要个同事写php的程序,就开始学习了PHP ,基础语法不用说了语言都是基本相通的,只是有若类型和强类型的区别(声明数据类型) 把现在看到的感觉有用的记录一下. $_SERVER['PHP_SEL ...

  3. Javascript中的集合

    集合是由一组无序且唯一(即不能重复)的项组成 function Set() { var items={}; this.has=function(value){ //return value in it ...

  4. CSUOJ_1001

    /* * Title : A+B(II) * Data : 2016/11/09 * Author : Andrew */ #include <iostream> #include < ...

  5. CentOS 6.3 安装过程

    1.放入光盘 2.安装欢迎界面 进入安装欢迎界面,有四个选项: 1.“Install or upgrade an existing system”:安装或升级现有系统 2. “Install syst ...

  6. Jmeter 学习(三)

    1. 线程组知识 1)Ramp-up period 表示多长时间内建立全部的线程数N 默认为0,表示测试开始即建立全部线程并立即发送访问请求 设置为Ts,表示每隔T/N建立一个线程 注1:一般不设置为 ...

  7. TestNG Study Note 1 - Eclipse 插件安装

    TestNG 插件在线安装 Help -> Install New Software -> Add -> Paste TestNG url to Add:  http://testn ...

  8. 程序设计入门——C语言 第6周编程练习 1 分解质因数(5分)

    1 分解质因数(5分) 题目内容: 每个非素数(合数)都可以写成几个素数(也可称为质数)相乘的形式,这几个素数就都叫做这个合数的质因数.比如,6可以被分解为2x3,而24可以被分解为2x2x2x3. ...

  9. Linux 命令——简约汇总

    1. 更改档案拥有者 命令 : chown [-cfhvR] [--help] [--version] user[:group] file... 功能 : 更改文件或者文件夹的拥有者 参数格式 :  ...

  10. JQuery_DOM 节点操作之包裹节点

    jQuery 提供了一系列方法用于包裹节点,那包裹节点是什么意思呢?其实就是使用字符串代码将指定元素的代码包含着的意思. <script type="text/javascript&q ...