CodeForces 618C CodeForces 618C

第一反应是在凸包上随便找一条边,然后找剩下n-2个点里面距离这条边最短的一个点,这三点就构成了符合要求的三角形。。然而。。精度被卡死。

换种思路,随便找两个点P1,P2,找剩下n-2个点中哪一个点与P1,P2形成的三角形面积最小,这三点构成了符合要求的三角形,然而我没写。。

最终这样写的,按X,Y进行排序,相邻三个判断是否三点共线即可

#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;

const int maxn=100000+10;
vector<int>v[maxn];
struct point
{
    int px,y;
    int x;
    int id;
}p[maxn];
int n;
int lshx[maxn];

bool cmp(const point&a,const point&b)
{
    if(a.px==b.px) return a.y<b.y;
    return a.px<b.px;
}

bool cmp1(const point&a,const point&b)
{
    return a.id<b.id;
}

long long multiply(point sp,point ep,point op)
{
    long long a=(long long)(sp.px-op.px);
    long long b=(long long)(ep.y-op.y);
    long long c=(long long)(ep.px-op.px);
    long long d=(long long)(sp.y-op.y);

    return a*b-c*d;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&p[i].px,&p[i].y);
        p[i].id=i;
    }
    sort(p+1,p+1+n,cmp);
    int tot=1;
    p[1].x=tot;
    for(int i=2;i<=n;i++)
    {
        if(p[i].px==p[i-1].px) p[i].x=p[i-1].x;
        else
        {
            tot++;
            p[i].x=tot;
        }
    }

    for(int i=1;i<=n;i++) v[p[i].x].push_back(p[i].id);
    sort(p+1,p+1+n,cmp1);
    if(v[1].size()>=2)
    {
        printf("%d %d ",v[1][0],v[1][1]);
        printf("%d\n",v[2][0]);
    }
    else if(v[2].size()>=2)
    {
        printf("%d ",v[1][0]);
        printf("%d %d\n",v[2][0],v[2][1]);
    }
    else
    {
        for(int i=3;i<=tot;i++)
        {
            if(v[i].size()>=2)
            {
                printf("%d ",v[i-1][0]);
                printf("%d %d\n",v[i][0],v[i][1]);
                break;
            }
            else
            {
                if(multiply(p[v[i][0]],p[v[i-1][0]],p[v[i-2][0]])==0) continue;
                else
                {
                    printf("%d %d %d\n",v[i][0],v[i-1][0],v[i-2][0]);
                    break;
                }
            }
        }
    }
    return 0;
}
时间: 2024-10-10 17:54:00

CodeForces 618C CodeForces 618C的相关文章

CodeForces 441E(Codeforces Round #252 (Div. 2))

思路:dp[i][now][mark][len]   i 表示当前第i 次now存的是后8位,mark为第9位为0还是1 len第九位往高位还有几位和第9位相等.  只存后8位的原因:操作只有200次每次都为加法的话后8位可以表示,如果为乘法第八位已知再加上第九位 和往前的长度已知,所以可以表示所有状态. 所存在问题就是 10 1111 1111 此时加上1之后 会变成 11 0000 0000 但这样并处影响结果 如果之后操作都为加法,只有200次,他不可能影响到前面的1, 乘法相当于左移也不

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Codeforces Educational Codeforces Round 15 C. Cellular Network

C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line

codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组版本 & 指针版本. (1)数组版本(短的字符串从高位处补0,直到跟长的字符串长度相同) 1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring>

【codeforces】Codeforces Round #277 (Div. 2) 解读

门户:Codeforces Round #277 (Div. 2) 486A. Calculating Function 裸公式= = #include <cstdio> #include <cstring> #include <algorithm> using namespace std ; typedef long long LL ; LL n ; int main () { while ( ~scanf ( "%I64d" , &n )

(最小生成树)Codeforces Educational Codeforces Round 9 Magic Matrix

You're given a matrix A of size n?×?n. Let's call the matrix with nonnegative elements magic if it is symmetric (so aij?=?aji), aii?=?0 and aij?≤?max(aik,?ajk) for all triples i,?j,?k. Note that i,?j,?k do not need to be distinct. Determine if the ma

(KMP、dp)Codeforces Educational Codeforces Round 21 G-Anthem of Berland

Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem. Though there are lots and lots of victories in history of Berland, there is the one that stand out the most.

CodeForces - 504A &amp;&amp; CodeForces - 624C &amp;&amp; CodeForces - 2B

Points 1. 关键要看到以度数为1的点作为突破口. 2. 关键是发现两者不同只能是a-c,而剩余的点必须为b 3. 注意0的情况.

codeforces Educational Codeforces Round 2 C Make Palindrome

C. Make Palindrome A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings &quo