Codeforces Round #340 (Div. 2) A B C D

http://codeforces.com/contest/617
A
尽量选择数值较大的

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
    int x;
    while (cin>>x)
    {
        int cnt = 0;
        while (x >= 5)
        {
            x -= 5;
            cnt++;
        }
        while (x >= 4)
        {
            x -= 4;
            cnt++;
        }
        while (x >= 3)
        {
            x -= 3;
            cnt++;
        }
        while (x >= 2)
        {
            x -= 2;
            cnt++;
        }
        while (x >= 1)
        {
            x -= 1;
            cnt++;
        }
        cout << cnt << endl;
    }
    return 0;
}

B
乘法计数原理

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

int n;
int a[110];
long long  b[110];


int main()
{
    while (scanf("%d", &n) != EOF)
    {
        int ok = 0;
        for (int i = 1;i <= n;i++)
        {
            scanf("%d", &a[i]);
            if (a[i] == 1)
                ok = 1;
        }
        if ((n == 1 && a[1] == 0) || !ok)
        {
            printf("0\n");
            continue;
        }

        memset(b, 1, sizeof(b));

        int len = 0;
        int c1 = 0;
        int cnt = 0;

        for (int i = 1;i <= n;i++)
        {
            if (a[i] == 1)
                c1++;
            else if (a[i] == 0 && c1 != 0)
                cnt++;

            if (c1 > 1 && a[i] == 1)
            {
                b[len++] = cnt + 1;
                cnt = 0;
            }

        }

        long long ans = 1;
        for (int i = 0;i < len;i++)
            ans *= b[i];

        printf("%lld\n", ans);
    }
    return 0;
}

C
按与水池1距离大到小模拟

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

struct Point
{
    Point() {}
    __int64 x, y;
}p[10],q[2010];

bool cmp(Point a,Point b)
{
    __int64 t1 = (a.x - p[0].x) * (a.x - p[0].x) + (a.y - p[0].y) * (a.y - p[0].y);
    __int64 t2 = (b.x - p[0].x) * (b.x - p[0].x) + (b.y - p[0].y) * (b.y - p[0].y);
    __int64 t3 = (a.x - p[1].x) * (a.x - p[1].x) + (a.y - p[1].y) * (a.y - p[1].y);
    __int64 t4 = (b.x - p[1].x) * (b.x - p[1].x) + (b.y - p[1].y) * (b.y - p[1].y);
    if (t1 == t2)
        return t3 > t4;
    else
        return t1 > t2;
}  

int main()
{
    int n;
    while (scanf("%d", &n) != EOF)
    {
        for (int i = 0;i < 2;i++)
            scanf("%I64d %I64d", &p[i].x, &p[i].y);

        for (int i = 0;i < n;i++)
            scanf("%I64d %I64d", &q[i].x, &q[i].y);

        sort(q, q + n, cmp);

        __int64 ans = 1e18, MAX = 0;
        for (int i = 0;i < n;i++)
        {
            ans = min(ans, MAX + (q[i].x - p[0].x) * (q[i].x - p[0].x) + (q[i].y - p[0].y)*(q[i].y - p[0].y));
            MAX = max(MAX, (q[i].x - p[1].x) * (q[i].x - p[1].x) +(q[i].y - p[1].y)*(q[i].y - p[1].y));
        }
        ans = min(ans, MAX);
        printf("%I64d\n" ,ans);
    }
    return 0;
}

D
三点一线 - 1
两点一线 另一点不在两点之间区域 - 2
其他 - 3

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

int x1, x2, x3, y11, y2, y3;

bool is_two(int x1, int y1, int x2, int y2, int x3, int y3)
{
    if (x1 == x2)
    {
        if (y3 <= min(y1, y2) || y3 >= max(y1, y2))
            return true;
        return false;
    }
    if (x1 == x3)
    {
        if (y2 <= min(y1, y3) || y2 >= max(y1, y3))
            return true;
        return false;
    }
    if (x3 == x2)
    {
        if (y1 <= min(y3, y2) || y1 >=max(y3, y2))
            return true;
        return false;
    }

    if (y1 == y2)
    {
        if (x3 <= min(x1, x2) || x3 >= max(x1, x2))
            return true;
        return false;
    }
    if (y1 == y3)
    {
        if (x2 <= min(x1, x3) || x2 >= max(x3, x1))
            return true;
        return false;
    }
    if (y3 == y2)
    {
        if (x1 <= min(x3, x2) || x1 >= max(x3, x2))
            return true;
        return false;
    }

    return false;
}

int main()
{
    while (cin >> x1 >> y11 >> x2 >> y2 >> x3 >> y3)
    {
        int ans;
        if (x1 == x2 && x1 == x3)
            ans = 1;
        else if (y11 == y2 && y2 == y3)
            ans = 1;
        else if (is_two(x1, y11, x2, y2, x3, y3))
        {
            ans = 2;
        }
        else
            ans = 3;
        cout << ans << endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值