题目链接:http://codeforces.com/contest/586/problem/B

B. Laurenty and Shop
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

A little boy Laurenty has been playing his favourite game Nota for quite a while and is now very hungry. The boy wants to make sausage and cheese sandwiches, but first, he needs to buy a sausage and some cheese.

The town where Laurenty lives in is not large. The houses in it are located in two rows, n houses in each row. Laurenty lives in the very last house of the second row. The only shop in town is placed in the first house of the first row.

The first and second rows are separated with the main avenue of the city. The adjacent houses of one row are separated by streets.

Each crosswalk of a street or an avenue has some traffic lights. In order to cross the street, you need to press a button on the traffic light, wait for a while for the green light and cross the street. Different traffic lights can have different waiting time.

The traffic light on the crosswalk from the j-th house of the i-th row to the (j + 1)-th house of the same row has waiting time equal to aij(1 ≤ i ≤ 2, 1 ≤ j ≤ n - 1). For the traffic light on the crossing from the j-th house of one row to the j-th house of another row the waiting time equals bj (1 ≤ j ≤ n). The city doesn't have any other crossings.

The boy wants to get to the store, buy the products and go back. The main avenue of the city is wide enough, so the boy wants to cross it exactly once on the way to the store and exactly once on the way back home. The boy would get bored if he had to walk the same way again, so he wants the way home to be different from the way to the store in at least one crossing.

Figure to the first sample.

Help Laurenty determine the minimum total time he needs to wait at the crossroads.

Input

The first line of the input contains integer n (2 ≤ n ≤ 50) — the number of houses in each row.

Each of the next two lines contains n - 1 space-separated integer — values aij (1 ≤ aij ≤ 100).

The last line contains n space-separated integers bj (1 ≤ bj ≤ 100).

Output

Print a single integer — the least total time Laurenty needs to wait at the crossroads, given that he crosses the avenue only once both on his way to the store and on his way back home.

Examples
input
4
1 2 3
3 2 1
3 2 2 3
output
12
input
3
1 2
3 3
2 1 3
output
11
input
2
1
1
1 1
output
4
Note

The first sample is shown on the figure above.

In the second sample, Laurenty's path can look as follows:

  • Laurenty crosses the avenue, the waiting time is 3;
  • Laurenty uses the second crossing in the first row, the waiting time is 2;
  • Laurenty uses the first crossing in the first row, the waiting time is 1;
  • Laurenty uses the first crossing in the first row, the waiting time is 1;
  • Laurenty crosses the avenue, the waiting time is 1;
  • Laurenty uses the second crossing in the second row, the waiting time is 3.

In total we get that the answer equals 11.

In the last sample Laurenty visits all the crossings, so the answer is 4.

因为走的路径形式要求非常严格,所以n幢房子就只有n种路径可供选择,直接暴力求出其中最小的和次小的相加即可。

#include<bits/stdc++.h>
using namespace std;
int n,a[][],b[]={};
int main()
{
cin>>n;
a[][]=a[][]=;
for(int row=;row<=;row++)
{
for(int i=;i<=n;i++)
{
cin>>a[row][i];
a[row][i]+=a[row][i-];
}
}
for(int i=;i<=n;i++)
{
cin>>b[i];
b[i]+=a[][i]+(a[][n]-a[][i]);
}
sort(b+,b+n+);
cout<<b[]+b[]<<endl;
}
#include<bits/stdc++.h>
using namespace std;
int n,a[][],b[]={};
int main()
{
cin>>n;
a[][]=a[][]=;
for(int row=;row<=;row++)
{
for(int i=;i<=n;i++)
{
cin>>a[row][i];
a[row][i]+=a[row][i-];
}
}
for(int i=;i<=n;i++)
{
cin>>b[i];
b[i]+=a[][i]+(a[][n]-a[][i]);
} int min2=0x3f3f3f3f,min1=min2-;
for(int i=;i<=n;i++)
{
if(b[i]<=min1)//b[i]<min1<min2
min2=min1,min1=b[i];
else if(b[i]<=min2)//min1<b[i]<min2
min2=b[i];
} cout<<min1+min2<<endl;
}

PS.求最小和次小分别用了快排和遍历,惊奇的发现在CF的测试样例下用快排居然比遍历快一倍……看来O(Cn)这个常数C在某些情况下也是有着明显的作用的。

───────────────────────────────────────────────────────────────────────────────────────

题目链接:http://codeforces.com/contest/586/problem/C

C. Gennady the Dentist
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.

All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with the value of his cofidence pi. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.

While Gennady treats the teeth of the i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.

If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of dj and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the j-th one in the line is reduced by the amount of dj.

All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.

Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

Input

The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.

Next n lines contain three integers each vi, di, pi (1 ≤ vi, di, pi ≤ 106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the i-th child.

Output

In the first line print number k — the number of children whose teeth Gennady will cure.

In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.

Examples
input
5
4 2 2
4 1 2
5 2 4
3 3 5
5 1 2
output
2
1 3
input
5
4 5 1
5 3 9
4 1 2
2 1 8
4 1 9
output
4
1 2 4 5
Note

In the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.

In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.

参考http://www.cnblogs.com/qscqesze/p/4873929.html的文章(里面说的第二个坑踩得我相当的艰辛QAQ)。

题意

一堆小孩要去看牙医,小孩进入牙医之后,就会发出叫声,使得接下来的v[i]个孩子的信心分别下降v[i],v[i]-......1这么多
如果小孩被吓跑了,他们又会叫,使得接下来的孩子发出d[i]的叫声
然后问你一共有多少人能够看病,并且是哪些人 题解: 数据范围只有4000,那就n^2暴力就好了
有两个坑点:
.爆int
.得v[i]减完之后,大家再一起叫d[i]的,不是边v[i]边d[i]
#include<bits/stdc++.h>
typedef long long ll;
const int MAXN = ;
using namespace std;
int n;
ll v[MAXN],d[MAXN],p[MAXN];
bool flag[MAXN];
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%I64d%I64d%I64d",&v[i],&d[i],&p[i]); int id[MAXN],cnt=;
for(int i=;i<=n;i++)
{
if(p[i]>=)//这个孩子看牙医了
{
id[cnt++]=i;//记录答案 ll de=v[i];//他的哭声对后面孩子的影响
for(int j=i+;j<=n;j++)
{
flag[j]=;
if(p[j]<) continue;
flag[j]=;
//标记他后面那些孩子中谁是依然有信心的 p[j]-=de;
if(de>) de--;
//信心down……
} ll sum=;//记录到第j个孩子之前所有直接被吓跑了的孩子对第j个孩子的影响
for(int j=i+;j<=n;j++)
{
if(p[j]>=) p[j]-=sum;
if(flag[j] && p[j]<) sum+=d[j];//如果这个孩子曾经有过信心,但是现在没了,说明他现在起正式跑路,进而对他后面的孩子产生影响
}
}
} printf("%d\n",cnt);
for(int i=;i<cnt;i++) printf("%s%d",(i!=)?" ":"",id[i]);
}

codeforces 586B/C的更多相关文章

  1. CodeForces 586B Laurenty and Shop

    F - Laurenty and Shop Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I ...

  2. codeforces 586B:Laurenty and Shop

    B. Laurenty and Shop time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. codeforces586B

    Laurenty and Shop CodeForces - 586B A little boy Laurenty has been playing his favourite game Nota f ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. 【剑指Offer学习】【面试题23:从上往下打印二叉树】

    题目:从上往下打印出二叉树的每一个结点,同一层的结点依照从左向右的顺序打印. 二叉树结点的定义: public static class BinaryTreeNode { int value; Bin ...

  2. Spring @Lazy

    @DependsOn用于强制初始化其他Bean.可以修饰Bean类或方法,使用该Annotation时可以指定一个字符串数组作为参数,每个数组元素对应于一个强制初始化的Bean. @DependsOn ...

  3. [AX2012]关于财务默认维度

    和以前的版本一样,AX2012中很多地方都使用财务维度,比如客户.销售订单.销售订单行等,根据相应的财务维度设置,生成的相应财务分录将带有财务维度,方便后续对财务分录交易的分析.下图是在客户记录上设置 ...

  4. Python 爬虫系列:糗事百科最热段子

    1.获取糗事百科url http://www.qiushibaike.com/hot/page/2/    末尾2指第2页 2.分析页面,找到段子部分的位置, 需要一点CSS和HTML的知识 3.编写 ...

  5. Linux应急响应(三):挖矿病毒

    0x00 前言 ​ 随着虚拟货币的疯狂炒作,利用挖矿脚本来实现流量变现,使得挖矿病毒成为不法分子利用最为频繁的攻击方式.新的挖矿攻击展现出了类似蠕虫的行为,并结合了高级攻击技术,以增加对目标服务器感染 ...

  6. 第7章 Ajax数据爬取

    Ajax 简介 Ajax 分析方法 Ajax 结果提取

  7. U3D教程宝典之两步实现超实用的XML存档

    两步实现超实用的XML存档 本套存档的优点:易使用,跨平台,防作弊(内容加密 + 防拷贝) 脚本下载地址 使用方法非常简单:把GameDataManager和XmlSaver两个脚本添加至工程后(1) ...

  8. Git的撤销与回滚

    1,commit 之前的撤销 未添加至暂存区的撤销(add 之前) git status git checkout . 已添加至暂存区的撤销(add 之后,有或者没有commit操作都可以执行) gi ...

  9. adc转换原理

    模数转换器即A/D转换器,或简称ADC,通常是指一个将模拟信号转变为数字信号的电子元件.通常的模数转换器是将一个输入电压信号转换为一个输出的数字信号.由于数字信号本身不具有实际意义,仅仅表示一个相对大 ...

  10. 敏捷开发中的Scrum流程和术语【转】

    任何人力流程都离不开人来执行,所以在讲解Scrum流程之前,有必要先把Scrum中的角色讲一下. 一天,一头猪和一只鸡在路上散步,鸡看了一下猪说,“嗨,我们合伙开一家餐馆怎么样?”,猪回头看了一下鸡说 ...