2012金华邀请赛解题报告

这次的没学过的算法多了起来。尽管我都猜对了是用什么算法(我仅仅知道大体上各算法的原理,但没写过。

。)。。还有翻译上的严重失误。这次太慘了。。。

差点挂零。。

这次比赛的pdf地址:http://poj.org/ProblemDescriptions/jinghua.pdf

A题:

题目地址:POJ 4044

因为上次我在低端题上的失误。。

已被队友嫌弃。。。已经被剥夺写签到题的权利。。。

可是这题竟然被他俩弄了2小时也没AC。

。于是我不得不把题目又一次翻译了遍,自己敲了代码。

然后AC。。这题刚開始翻译错了,那个units digit在这里是个位数的意思。。sad。。

。题目非常easy。。直接上代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;

int main()
{
    int t, n1, n2, i, j, n, m, x, pos1, pos2, max1, s, k, n3;
    int hash1[110], a[100], b[100], hash2[110], c[100];
    scanf("%d",&t);
    while(t--)
    {
        max1=-1;
        scanf("%d%d",&n,&m);
        memset(hash1,0,sizeof(hash1));
        memset(hash2,0,sizeof(hash2));
        for(i=0; i<n; i++)
        {
            scanf("%d",&x);
            hash1[x]++;
        }
        for(i=0; i<m; i++)
        {
            scanf("%d",&x);
            hash2[x]++;
        }
        n1=0;
        n2=0;
        for(i=100; i>=0; i--)
        {
            if(hash1[i])
            {
                a[n1++]=i;
            }
            if(hash2[i])
            {
                b[n2++]=i;
            }
        }
        for(i=0; i<n1; i++)
        {
            for(j=0; j<n2; j++)
            {
                if(a[i]==b[j])
                {
                    s=1;
                    for(k=1; i+k<n1&&j+k<n2; k++)
                    {
                        if(a[i+k]==b[j+k])
                        {
                            s++;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if(max1<s)
                    {
                        max1=s;
                        pos1=i;
                    }
                    break;
                }
            }
        }
        if(max1==-1)
        {
            printf("NONE
");
            continue ;
        }
        n3=0;
        for(i=pos1;i<pos1+max1;i++)
        {
            c[n3++]=a[i];
        }
        for(i=0;i<n3;i++)
        {
            printf("%d ",c[i]);
        }
        printf("
");
        for(i=0;i<10;i++)
        {
            for(j=n3-1;j>=0;j--)
            {
                if(c[j]%10==i)
                {
                    printf("%d ",c[j]);
                }
            }
        }
        printf("
");
    }
    return 0;
}

E题:

题目地址:POJ 4048

这题是shijun翻译的,他把题目意思翻译给了我跟+才。可是我理解的意思竟然跟他的原本意思相反,。更奇妙的是我理解的意思就是题目本来的意思。

。shijun翻译错了。

。。当时我感觉我的想法全然可行。。可是当场被他俩反驳了。。我以为是我理解错了意思。

。结果赛后找题解才发现。。那正确思路跟我当时想的做法是一模一样的。。。简直sad。

。。。因为昨晚有CF,也就没敲,今早起来一敲,把线段相交的模板一套。

就AC了。。

题目的思路是枚举线段的端点,每次把端点与原点形成一条射线。再遍历线段,求交点数。最后最多的交点数就是答案。复杂度1500*3000,轻松无压力。

代码例如以下:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;
#define eps 1e-9
struct point
{
    double x;
    double y;
}p[4000];
int inter(point a, point b, point c, point d)
{
    if(min(a.x, b.x) > max(c.x, d.x) ||
            min(a.y, b.y) > max(c.y, d.y) ||
            min(c.x, d.x) > max(a.x, b.x) ||
            min(c.y, d.y) > max(a.y, b.y) )
        return 0;
    double h, i, j, k;
    h = (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x);
    i = (b.x-a.x)*(d.y-a.y) - (b.y-a.y)*(d.x-a.x);
    j = (d.x-c.x)*(a.y-c.y) - (d.y-c.y)*(a.x-c.x);
    k = (d.x-c.x)*(b.y-c.y) - (d.y-c.y)*(b.x-c.x);
    return h*i <= eps && j*k <= eps;
}
int main()
{
    int t, n, i, j, n0, ans, max1;
    double x, y;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        n0=0;
        max1=-1;
        for(i=0;i<2*n;i++)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        scanf("%lf%lf",&x,&y);
        for(i=0;i<2*n;i++)
        {
            p[i].x-=x;
            p[i].y-=y;
        }
        point t1;
        t1.x=0;
        t1.y=0;
        for(i=0;i<2*n;i++)
        {
            point t2;
            t2.x=p[i].x*20000;
            t2.y=p[i].y*20000;
            ans=0;
            for(j=0;j<2*n;j+=2)
            {
                if(inter(t1,t2,p[j],p[j+1]))
                {
                    ans++;
                }
            }
            if(max1<ans)
                max1=ans;
        }
        printf("%d
",max1);
    }
    return 0;
}


原文地址:https://www.cnblogs.com/claireyuancy/p/6790179.html