2012金华邀请赛解题报告

来源:互联网 发布:linux虚拟机串口调试 编辑:程序博客网 时间:2024/06/10 09:24

这次的没学过的算法多了起来,虽然我都猜对了是用什么算法(我只知道大体上各算法的原理,但没写过。。)。。还有翻译上的严重失误。这次太惨了。。。差点挂零。。

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

A题:

题目地址:POJ 4044

由于上次我在低端题上的失误。。已被队友嫌弃。。。已经被剥夺写签到题的权利。。。但是这题居然被他俩弄了2小时也没AC。。。于是我不得不把题目重新翻译了遍,自己敲了代码。然后AC。。这题刚开始翻译错了,那个units digit在这里是个位数的意思。。sad。。。题目很简单。。直接上代码:

#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\n");            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("\n");        for(i=0;i<10;i++)        {            for(j=n3-1;j>=0;j--)            {                if(c[j]%10==i)                {                    printf("%d ",c[j]);                }            }        }        printf("\n");    }    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-9struct 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\n",max1);    }    return 0;}


0 0
原创粉丝点击