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 / - N;
int y = N - x;
printf("%d %d\n", x, y);
}
return ;
}
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-;
const double pi=acos(-1.0);
int sgn(double x)
{
if (fabs(x)<eps) return ;
if (x<) return -;
return ;
}
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))<= &&
sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e))<=;
}
Point o;
bool _cmp(Point p1,Point p2)
{
double tmp=(p1-o)^(p2-o);
if (sgn(tmp)>) return true;
else if (sgn(tmp)== && sgn(dist(p1,o)-dist(p2,o))<=) return true;
else return false;
} bool OnSeg(Point P,Line L)
{
return
sgn((L.s-P)^(L.e-P))== &&
sgn((P.x-L.s.x)*(P.x-L.e.x))<= &&
sgn((P.y-L.s.y)*(P.y-L.e.y))<=;
}
int inConvexPoly(Point a,Point p[],int n)
{
for (int i=;i<n;i++)
{
if (sgn((p[i]-a)^(p[(i+)%n]-a))<) return -; // out
else if (OnSeg(a,Line(p[i],p[(i+)%n]))) return ; // on
}
return ; // in
} Point p[]; int main()
{
int t;
scanf("%d",&t);
while (t--)
{
for (int i=;i<;i++) scanf("%lf%lf",&p[i].x,&p[i].y);
bool xj=false;
for (int i=;i<;i++)
{
for (int j=;j<;j++)
{
Line l1=Line(p[i],p[(i+)%]);
Line l2=Line(p[j+],p[(j+)%+]);
if (inter(l1,l2))
{
xj=true;
break;
}
}
if (xj) break;
}
if (xj)
{
printf("intersect\n");
continue;
}
int in1=,in2=;
o=(p[]+p[]+p[])/3.0;
sort(p,p+,_cmp);
o=(p[]+p[]+p[])/3.0;
sort(p+,p+,_cmp);
for (int i=;i<;i++)
{
if (inConvexPoly(p[i],p+,)==) in1++;
if (inConvexPoly(p[i+],p,)==) in2++;
}
if (in1==||in2==) printf("contain\n");
else printf("disjoint\n");
}
return ;
}
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 + ; int Next[maxn]; void getNext(char x[], int m, int next[]) {
int i, j;
j = next[] = -;
i = ;
while(i < m) {
while(- != 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 = ;
getNext(x, m, Next);
i = j = ;
while(i < n) {
while(- != 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[] == '' && ly == ) {
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 = ; i < ly / ; i ++)
swap(y[i], y[ly - i - ]); if(KMP_Count(y, ly, x, lx)) {
printf("Alice\n");
continue;
}
printf("Bob\n"); }
}
return ;
}
人生第一个 KMP 模板题吧算是
2019省赛训练组队赛3.31周四-17fj的更多相关文章
- 2019省赛训练组队赛3.26周二---FJUT 2016
A.Minimum’s Revenge There is a graph of n vertices which are indexed from 1 to n. For any pair of di ...
- hdu6578 2019湖南省赛D题Modulo Nine 经典dp
目录 题目 解析 AC_Code @ 题目 第一题题意是一共有{0,1,2,3}四种数字供选择,问有多少个长度为n的序列满足所有m个条件,每个条件是说区间[L,R]内必须有恰好x个不同的数字. 第二题 ...
- 2019牛客训练赛第七场 C Governing sand 权值线段树+贪心
Governing sand 题意 森林里有m种树木,每种树木有一定高度,并且砍掉他要消耗一定的代价,问消耗最少多少代价可以使得森林中最高的树木大于所有树的一半 分析 复杂度分析:n 1e5种树木,并 ...
- QFNU-ACM 2019.5.23组队赛 2019山东省赛复现
A.Calandar 题意:一年12个月,一个月30天,5天一周,已知某天的年月日星期数,求所给年月日的星期数是多少 思路:直接进行计算,其实每个月每年都是等长度的就使得计算的时候忽略年月,可以直接进 ...
- X-NUCA 2017 web专题赛训练题 阳光总在风雨后和default wp
0X0.前言 X-NUCA 2017来了,想起2016 web专题赛,题目都打不开,希望这次主办方能够搞好点吧!还没开赛,依照惯例会有赛前指导,放一些训练题让CTFer们好感受一下题目. 题目有一大 ...
- acm省赛选拔组队赛经验谈
省赛组队赛已经进行5场了,过半了. 从曾经的不会组队到如今逐渐磨合,尽管每次都有遗憾,可是我认为我们一直在进步.有些失误是要记录下来下次不能再犯的! 经验: 1:上场開始一定要有人(英语能力和算法综合 ...
- 2019新生赛 %%%xxh
笔记.md ...
- Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)
题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...
- PTA天梯赛训练题L1-064:估值一亿的AI核心代码(字符串模拟)
Update:smz说regex秒过Orz,yzd记在这里了. 听说今年天梯赛有个烦人的模拟,我便被队友逼着试做一下……一发15,二发20.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...
随机推荐
- LeetCode算法题-Valid Anagram(Java实现)
这是悦乐书的第198次更新,第205篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第61题(顺位题号是242).给定两个字符串s和t,写一个函数来确定t是否是s的anag ...
- 力扣算法题—069x的平方根
实现 int sqrt(int x) 函数. 计算并返回 x 的平方根,其中 x 是非负整数. 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去. 示例 1: 输入: 4 输出: 2 示例 ...
- Maven——settings.xml配置
settings.xml配置 原文 <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed ...
- 用js检测文本框中输入的是否符合条件并有错误和正确提醒
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 转://利用从awr中查找好的执行计划来优化SQL
原文地址:http://blog.csdn.net/zengxuewen2045/article/details/53495613 同事反应系统慢,看下是不是有锁了,登入数据库检查,没有异常锁定,但发 ...
- LNMP安装,FastCGI说明
1.1.工作原理讲解说明 1. 用户请求的静态文件,由nginx服务器处理,根据静态的location配置进行处理 用户请求的动态文件,由php服务进行处理,根据动态的location配置进行处理 2 ...
- 高精度除法(b为int类型)
#include<iostream> #include<cstring> #include<cstdio> using namespace std; ],a[],b ...
- 初学Python——Socket网络编程
认识socket socket本质上就是在2台网络互通的电脑之间,架设一个通道,两台电脑通过这个通道来实现数据的互相传递.我们知道网络 通信 都 是基于 ip+port(端口) 方能定位到目标的具体机 ...
- ASP.NET Core - 关于Tag Helper值得了解的五点
如果您开发过ASP.NET Core Web应用程序,您应该已经熟悉了Tag Helper.ASP.NET Core应用程序依赖Tag Helper来呈现表单和表单字段是很常见的.所以,一个视图通常包 ...
- buildroot使用介绍
buildroot是Linux平台上一个构建嵌入式Linux系统的框架.整个Buildroot是由Makefile脚本和Kconfig配置文件构成的.你可以和编译Linux内核一样,通过buildro ...