2019省赛训练组队赛3.31周四-17fj

https://vjudge.net/contest/289558#overview

 

A - Frog

 

 

Therearex frogs and y chicken in a garden. Kim found there are n heads and m legs in the garden. Please tell Kim how many frogs and chicken are there. (A frog has 4 legs, and a chicken has 2 legs.)

Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: Two number n and m.

1<=n, m <=100000. The data is legal.

Output

For each test case, output two numbers A and B – the number of frog and the number of chicken.

Sample Input

2
2 6
2 4

Sample Output

1 1
0 2

代码:

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

int T;
int N, M;

int main() {
    scanf("%d", &T);
    while(T --) {
        scanf("%d%d", &N, &M);
        int x = M / 2 - N;
        int y = N - x;
        printf("%d %d\n", x, y);
    }
    return 0;
}
View Code

B - Triangles

 

This is a simple problem. Given two triangles A and B, you should determine they are intersect, contain or disjoint. (Public edge or point are treated as intersect.)

Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: X1 Y1 X2 Y2 X3 Y3 X4 Y4 X5 Y5 X6 Y6. All the coordinate are integer. (X1,Y1) , (X2,Y2), (X3,Y3) forms triangles A ; (X4,Y4) , (X5,Y5), (X6,Y6) forms triangles B.

-10000<=All the coordinate <=10000

Output

For each test case, output “intersect”, “contain” or “disjoint”.

Sample Input

2
0 0 0 1 1 0 10 10 9 9 9 10
0 0 1 1 1 0 0 0 1 1 0 1

Sample Output

disjoint 
intersect 

代码(模板题??? 比赛的时候 wa 到怀疑人生):

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

const double eps=1e-8;
const double pi=acos(-1.0);
int sgn(double x)
{
    if (fabs(x)<eps) return 0;
    if (x<0) return -1;
    return 1;
}
struct Point
{
    double x,y;
    Point() {}
    Point(double _x,double _y)
    {
        x=_x;
        y=_y;
    }
    Point operator +(const Point &b) const
    {
        return Point(x+b.x,y+b.x);
    }
    Point operator -(const Point &b) const
    {
//        return Point(x-b.x,y-b.x);
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b) const
    {
        return x*b.y-y*b.x;
    }
    double operator *(const Point &b) const
    {
        return x*b.x+y*b.y;
    }
    Point operator /(const double b) const
    {
        return Point(x/b,y/b);
    }
};

struct Line
{
    Point s,e;
    Line() {}
    Line(Point _s,Point _e)
    {
        s=_s;
        e=_e;
    }
};

double dist(Point a,Point b)
{
    return sqrt((a-b)*(a-b));
}
bool inter(Line l1,Line l2)
{
    return
        max(l1.s.x,l1.e.x)>=min(l2.s.x,l2.e.x) &&
        max(l2.s.x,l2.e.x)>=min(l1.s.x,l1.e.x) &&
        max(l1.s.y,l1.e.y)>=min(l2.s.y,l2.e.y) &&
        max(l2.s.y,l2.e.y)>=min(l1.s.y,l1.e.y) &&
        sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e))<=0 &&
        sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=0;
}
Point o;
bool _cmp(Point p1,Point p2)
{
    double tmp=(p1-o)^(p2-o);
    if (sgn(tmp)>0) return true;
    else if (sgn(tmp)==0 && sgn(dist(p1,o)-dist(p2,o))<=0) return true;
    else return false;
}

bool OnSeg(Point P,Line L)
{
    return
        sgn((L.s-P)^(L.e-P))==0 &&
        sgn((P.x-L.s.x)*(P.x-L.e.x))<=0 &&
        sgn((P.y-L.s.y)*(P.y-L.e.y))<=0;
}
int inConvexPoly(Point a,Point p[],int n)
{
    for (int i=0;i<n;i++)
    {
        if (sgn((p[i]-a)^(p[(i+1)%n]-a))<0) return -1;  // out
        else if (OnSeg(a,Line(p[i],p[(i+1)%n]))) return 0;  // on
    }
    return 1; // in
}

Point p[6];


int main()
{
    int t;
    scanf("%d",&t);
    while (t--)
    {
        for (int i=0;i<6;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
        bool xj=false;
        for (int i=0;i<3;i++)
        {
            for (int j=0;j<3;j++)
            {
                Line l1=Line(p[i],p[(i+1)%3]);
                Line l2=Line(p[j+3],p[(j+1)%3+3]);
                if (inter(l1,l2))
                {
                    xj=true;
                    break;
                }
            }
            if (xj) break;
        }
        if (xj)
        {
            printf("intersect\n");
            continue;
        }
        int in1=0,in2=0;
        o=(p[0]+p[1]+p[2])/3.0;
        sort(p,p+3,_cmp);
        o=(p[3]+p[4]+p[5])/3.0;
        sort(p+3,p+6,_cmp);
        for (int i=0;i<3;i++)
        {
            if (inConvexPoly(p[i],p+3,3)==1) in1++;
            if (inConvexPoly(p[i+3],p,3)==1) in2++;
        }
        if (in1==3||in2==3) printf("contain\n");
        else printf("disjoint\n");
    }
    return 0;
}
View Code

D - Game

 

Alice and Bob is playing a game.

Each of them has a number. Alice’s number is A, and Bob’s number is B.

Each turn, one player can do one of the following actions on his own number:

1. Flip: Flip the number. Suppose X = 123456 and after flip, X = 654321

2. Divide. X = X/10. Attention all the numbers are integer. For example X=123456 , after this action X become 12345(but not 12345.6). 0/0=0.

Alice and Bob moves in turn, Alice moves first. Alice can only modify A, Bob can only modify B. If A=B after any player’s action, then Alice win. Otherwise the game keep going on!

Alice wants to win the game, but Bob will try his best to stop Alice.

Suppose Alice and Bob are clever enough, now Alice wants to know whether she can win the game in limited step or the game will never end.

Input

First line contains an integer T (1 ≤ T ≤ 10), represents there are T test cases.

For each test case: Two number A and B. 0<=A,B<=10^100000.

Output

For each test case, if Alice can win the game, output “Alice”. Otherwise output “Bob”.

Sample Input

4
11111 1
1 11111
12345 54321
123 123

Sample Output

Alice
Bob
Alice
Alice

Hint

For the third sample, Alice flip his number and win the game.

For the last sample, A=B, so Alice win the game immediately even nobody take a move.

代码:

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int maxn = 1e5 + 10;


int Next[maxn];

void getNext(char x[], int m, int next[]) {
    int i, j;
    j = next[0] = -1;
    i = 0;
    while(i < m) {
        while(-1 != j && x[i] != x[j])
            j = next[j];
        next[++ i] = ++ j;
    }
}

int KMP_Count(char x[], int m, char y[], int n)
{
    int i, j;
    int ans = 0;
    getNext(x, m, Next);
    i = j = 0;
    while(i < n) {
        while(-1 != j && y[i] != x[j])
            j = Next[j];
        i ++;
        j ++;
        if(j >= m) {
            ans ++;
            j = Next[j];
        }
    }
    return ans;
}

int main() {
    char x[maxn];
    char y[maxn];
    char p[maxn];
    int T;
    scanf("%d", &T);
    while(T --) {

        scanf("%s%s", x, y);

        int lx = strlen(x);
        int ly = strlen(y);
        if(y[0] == '0' && ly == 1) {
            printf("Alice\n");
            continue;
        }
        if(ly > lx) printf("Bob\n");
        else {
            if(KMP_Count(y, ly, x, lx)) {
                printf("Alice\n");
                continue;
            }

            for(int i = 0; i < ly / 2; i ++)
                swap(y[i], y[ly - i - 1]);

            if(KMP_Count(y, ly, x, lx)) {
                printf("Alice\n");
                continue;
            }
            printf("Bob\n");

        }
    }
    return 0;
}
View Code

人生第一个 KMP 模板题吧算是

posted @ 2019-03-21 23:13  丧心病狂工科女  阅读(233)  评论(0编辑  收藏  举报