ACM ICPC 2017 Warmup Contest 5

14 篇文章 0 订阅
4 篇文章 0 订阅

据说似乎是挂错题了,三道水题,估计是某比赛的热身赛吧

结果系统还炸了,什么thin pool溢出,什么测评姬无数据,各种ce

好在最后时刻成功ak了,想想这似乎是我除大一上机50+题ak后时隔两年后的第一次ak,玄学

 

 

 A. Advice from Jad

思路:简单的字符串匹配,一开始看到的时候,对于字符串渣渣的我来说有点蒙,然而这题确实有点水,一开始以为是个前缀或模式匹配什么的,后来发现kmp都用不到 ,直接O(mn)强行匹配就好了

 

/*
Author Owen_Q
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 110;

char ep[10][maxn];
char icpcp[10][maxn];
int len[10];

int main()
{
    int n,m,tt;
    while(scanf("%d",&tt)!=EOF)
    {
        for(int t=1;t<=tt;t++)
        {
            scanf("%d%d",&n,&m);
            getchar();
            for(int i=0;i<n;i++)
            {
                gets(ep[i]);
                len[i] = strlen(ep[i]);
            }
            for(int i=0;i<m;i++)
            {
                gets(icpcp[i]);
            }
            printf("Case #%d:\n",t);
            for(int i=0;i<m;i++)
            {
                bool diff = true;
                int icpclen = strlen(icpcp[i]);
                //cout << icpclen << "*"<<endl;
                for(int j=0;diff&&j<n;j++)
                {
                    int pos = 0;
                    for(int k=0;k<icpclen&&pos<len[j];k++)
                    {
                        if(icpcp[i][k] != ep[j][pos])
                        {
                            break;
                        }
                        else
                        {
                            pos++;
                        }
                    }
                    if(pos >= len[j])
                    {
                        diff = false;
                    }
                    //cout << pos << "***" << endl;
                }
                if(diff)
                {
                    printf("This problem may be somewhat difficult.\n");
                }
                else
                {
                    printf("This is an easy problem.\n");
                }
            }
            printf("\n");
        }
    }
    return 0;
}

 

 

 

C. Chat Parser

 

思路:其实这题和上题差不多,也是字符串匹配,就是这回按行读,且不知道串长,迫不得已开string,用cin,关同步,并存储于map,就ok了

/*
Author Owen_Q
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 1e5+10;

string s;
map<string,bool> p;

int main()
{
	ios::sync_with_stdio(false); 
    int tt;
    while(cin>>tt)
    {
        getchar();
        for(int t=1;t<=tt;t++)
        {
            p.clear();
            while(getline(cin,s))
            {
                int len = s.size();
                if(len==0)
                {
                    break;
                }
                int pos;
                for(pos=0;pos<len;pos++)
                {
                    if(s[pos] == ':')
                        break;
                }
                string ns = s.substr(0,pos);
                p[ns] = true;
            }
            cout << "Case #" << t << ": " << p.size()<<endl;
        }
    }
    return 0;
}

 

 

 

 B. Boats on the lake

思路:计算几何,判断点在多边形内部,利用射线交点奇偶性来判断,对于边缘点,特判点在直线上就好了,感觉计算几何这块可以稍微整理一下

 

/*
Author Owen_Q
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

const int maxn = 110;

double bx[maxn],by[maxn],polyX[maxn],polyY[maxn];

bool pointInPolygon(int ployCorners,double x,double y);


int main()
{
    int tt;
    while(scanf("%d",&tt)!=EOF)
    {
        for(int t=1;t<=tt;t++)
        {
            printf("Case #%d:\n",t);
            int n;
            scanf("%d",&n);
            for(int i=1;i<=n;i++)
            {
                scanf("%lf%lf",&bx[i],&by[i]);
            }
            int m;
            scanf("%d",&m);
            for(int i=0;i<m;i++)
            {
                int sum = 0;
                int p;
                scanf("%d",&p);
                for(int j=0;j<p;j++)
                {
                    int pos;
                    scanf("%d",&pos);
                    polyX[j] = bx[pos];
                    polyY[j] = by[pos];
                }
                for(int j=1;j<=n;j++)
                {
                    if(pointInPolygon(p,bx[j],by[j]))
                    {
                        sum++;
                    }
                }
               // cout << pointInPolygon(p,tx,ty,0,15) << endl;
                /*for(int j=0;j<p;j++)
                {
                    cout << tx[j] << " " << endl;
                }*/
                printf("%d\n",sum);
            }
        }
    }
    return 0;
}


//  Globals which should be set before calling this function:
//
//  int    polyCorners  =  how many corners the polygon has
//  float  polyX[]      =  horizontal coordinates of corners
//  float  polyY[]      =  vertical coordinates of corners
//  float  x, y         =  point to be tested
//
//  (Globals are used in this example for purposes of speed.  Change as
//  desired.)
//
//  The function will return YES if the point x,y is inside the polygon, or
//  NO if it is not.  If the point is exactly on the edge of the polygon,
//  then the function may return YES or NO.
//
//  Note that division by zero is avoided because the division is protected
//  by the "if" clause which surrounds it.



double getdis(double ax,double ay,double bx,double by)
{
    return sqrt((ax-bx)*(ax-bx) + (ay-by)*(ay-by));
}

bool inLine(double px,double py,double ax,double ay,double bx,double by)
{
    //cout << ax << "^^" << ay << "^^" << bx << "^^" << by << endl;
    double ap = getdis(ax,ay,px,py);
    double bp = getdis(bx,by,px,py);
    double ab = getdis(ax,ay,bx,by) + 1e-8;
    if(ap+bp<=ab)
    {
        //cout << ap << "#" << bp << "#" << ab << endl;
        return true;
    }
    else
    {
        //cout << ap << "#" << bp << "#" << ab << endl;
        return false;
    }
}

bool pointInPolygon(int polyCorners,double x,double y)
{
    /*for(int j=0;j<polyCorners;j++)
            {
                cout << polyX[j] << " " << endl;
            }*/
    int   i, j=polyCorners-1 ;

    for(i=0;i<j;i++)
    {
        if(inLine(x,y,polyX[i],polyY[i],polyX[i+1],polyY[i+1]))
        {
            //cout << "*"<<i+1 <<"*"<<x<<"*"<<y<<"*"<<polyX[i]<<"*"<<polyY[i]<<"*"<<polyX[i+1]<<"*"<<polyY[i+1]<< endl;
            return true;
        }
    }
    if(inLine(x,y,polyX[j],polyY[j],polyX[0],polyY[0]))
    {
        return true;
    }

    bool  oddNodes=false ;

    for (i=0; i<polyCorners; i++)
    {
        if (((polyY[i]< y && polyY[j]>=y)
        ||   (polyY[j]< y && polyY[i]>=y))
        &&   (polyX[i]<=x || polyX[j]<=x) )
        {
            oddNodes^=(polyX[i]+(y-polyY[i])/(polyY[j]-polyY[i])*(polyX[j]-polyX[i])<x);
        }
        j=i;
    }

    //cout << "**" << endl;
    return oddNodes;
}



 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值