Codeforces Round #340 (Div. 2) 总结

123 篇文章 0 订阅
A. Elephant
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1234 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.

Input

The first line of the input contains an integer x (1 ≤ x ≤ 1 000 000) — The coordinate of the friend's house.

Output

Print the minimum number of steps that elephant needs to make to get from point 0 to point x.

Sample test(s)
input
5
output
1
input
12
output
3
Note

In the first sample the elephant needs to make one step of length 5 to reach the point x.

In the second sample the elephant can get to point x if he moves by 35 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves.

题意:求从0变到数字n最少需要多少步,每次可以增加1,2,3,4,5.
解:答案直接就是n/5+(n%5=0?0:1);
<span style="font-size:14px;">#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        int sum=0;
        sum+=n/5;
        if(n%5!=0)
            sum++;
        printf("%d\n",sum);
    }
    return 0;
}</span>

B. Chocolate
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.

You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't.

Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

Input

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar.

The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Output

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

Sample test(s)
input
3
0 1 0
output
1
input
5
1 0 1 0 1
output
4
Note

In the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.

In the second sample you can break the bar in four ways:

10|10|1

1|010|1

10|1|01

1|01|01

题意:一窜数字,可以分成很多段,每段里面最少有一个1。求所有情况有多少
解:组合问题
#include<bits/stdc++.h>
using namespace std;
int a[200];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int temp=0;
        for(int i=1;i<=n;i++)
            {
                scanf("%d",&a[i]);
                if(a[i]==1)
                    temp=1;
            }
            if(temp==0)
            {
                printf("0\n");
                continue;
            }
            int i=0;
            while(a[i]==0)
            {
                i++;
            }
            while(a[n]==0)
            {
                n--;
            }
            long long sum=1;
            int cnt=0;
            int cc=0;
            for(int j=i+1;j<=n-1;j++)
            {
                if(a[j]!=1)
                {
                    cc=1;
                }
            }
            if(cc==0)
            {
                printf("1\n");
                continue;
            }
            for(int j=i+1;j<=n;j++)
            {
                if(a[j]==0)
                {
                    cnt++;
                }
                if(a[j]==1)
                {
                    if(cnt!=0)
                    sum*=(cnt+1);
                    cnt=0;
                }
            }
            printf("%lld\n",sum);
    }
}
C. Watering Flowers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A flowerbed has many flowers and two fountains.

You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, the distance between the flower and the first fountain doesn't exceed r1, or the distance to the second fountain doesn't exceed r2. It's OK if some flowers are watered by both fountains.

You need to decrease the amount of water you need, that is set such r1 and r2 that all the flowers are watered and the r12 + r22 is minimum possible. Find this minimum value.

Input

The first line of the input contains integers nx1y1x2y2 (1 ≤ n ≤ 2000 - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain.

Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flower.

It is guaranteed that all n + 2 points in the input are distinct.

Output

Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.

Sample test(s)
input
2 -1 0 5 3
0 2
5 2
output
6
input
4 0 0 5 0
9 4
8 3
-1 0
1 4
output
33
Note

The first sample is (r12 = 5r22 = 1):The second sample is (r12 = 1r22 = 32):

题意:两个水源要喷水给花,求在必须浇灌每朵花的情况下,r1^2+r2^2最小。
解:枚举每朵花到S1的最大距离,然后S2的距离求最小。
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define LL long long
const LL maxm=1e4+10;
const LL inf=1e18+10;
struct node
{
    LL x,y;
    LL dr1,dr2;
}t[maxm];
LL distance(LL x1,LL y1,LL x2,LL y2)
{
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}
int main()
{
    LL n,x1,y1,x2,y2;
    while(scanf("%lld%lld%lld%lld%lld",&n,&x1,&y1,&x2,&y2)!=EOF)
    {
        for(LL i=0;i<n;i++)
        {
            scanf("%lld%lld",&t[i].x,&t[i].y);
            t[i].dr1=distance(t[i].x,t[i].y,x1,y1);
            t[i].dr2=distance(t[i].x,t[i].y,x2,y2);
        }
        LL ans=inf;
        for(LL i=0;i<n;i++)
        {
            LL R1=t[i].dr1;
            LL R2=0;
            for(LL j=0;j<n;j++)
            {
                if(t[j].dr1>R1)
                {
                    R2=max(R2,t[j].dr2);
                }
            }
            ans=min(ans,R1+R2);
        }
        for(LL i=0;i<n;i++)
        {
            LL R1=t[i].dr2;
            LL R2=0;
            for(LL j=0;j<n;j++)
            {
                if(t[j].dr2>R1)
                {
                    R2=max(R2,t[j].dr1);
                }
            }
            ans=min(ans,R1+R2);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

D. Polyline
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.

Input

Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.

Output

Print a single number — the minimum possible number of segments of the polyline.

Sample test(s)
input
1 -1
1 1
1 2
output
1
input
-1 -1
-1 3
4 3
output
2
input
1 1
2 3
3 2
output
3
Note

The variant of the polyline in the first sample:The variant of the polyline in the second sample:The variant of the polyline in the third sample:

题意:要是三个点在一条直线,输出1;可以构成二中的就输出2,;否则3;

解:枚举每种情况就行了

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int x1,x2,x3,u1,u2,u3;
    while(scanf("%d%d%d%d%d%d",&x1,&u1,&x2,&u2,&x3,&u3)!=EOF)
    {
        if((x1 == x2 && x2 == x3) || (u1 == u2 && u1 == u3))
        {
            printf("1\n");
            continue;
        }
        if((x1 == x2 && (u3 >= max(u1,u2) || u3 <= min(u1,u2))) || (x1 == x3 && (u2 >= max(u1,u3) || u2 <= min(u1,u3))) || (x2 == x3 && (u1 >= max(u2,u3) || u1 <= min(u2,u3))) || (u2 == u1 && (x3 >= max(x1,x2) || x3 <= min(x1,x2))) || (u3 == u2 && (x1 >= max(x2,x3) || x1 <= min(x2,x3))) || (u3 == u1 && (x2 >= max(x1,x3) || x2 <= min(x1,x3))))
        {
            printf("2\n");
            continue;
        }
        printf("3\n");
    }
    return 0;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值