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.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...
 
随机推荐
- js 编辑数组
			
删除数组第一个元素使用var length = arr.shift(); 删除arr的第一个元素后, 返回值是删除后的数组长度 删除数组最后一个元素使用var length = a ...
 - js中split()方法得到的数组长度
			
js 中split(",")方法通过 ”,“ 分割字符串, 如果字符串中没有 “,” , 返回的是字符串本身 var str = “abc”://分隔符个数为0 var newSt ...
 - python 初始socket
			
一.网络基础 1.c\s架构:客户端英文名称:Client(使用服务端的服务),服务端英文名称:Server 软件c\s架构:QQ.微信.优酷.暴风影音.浏览器(IE.火狐,360浏览器等): 软件b ...
 - linux 软连接创建  压缩解压缩  linux的dns服务相关
			
linux软连接创建 注意用绝对路径,语法如下 ln -s 目标文件绝对路径 软连接名字绝对路径 ln -s /小护士.txt /tmp/hs.txt 修改linux的PS1变量,命令提示符变量 PS ...
 - C++ 参数传值 与 传引用
			
参数传值 在 C++ 中,函数参数的传递有两种方式:传值和传引用.在函数的形参不是引用的情况下,参数传递方式是传值的.传引用的方式要求函数的形参是引用.“传值”是指,函数的形参是实参的一个拷贝,在函数 ...
 - 转://Oracle打补丁方法论
			
成熟的IT企业,往往会有自己的补丁计划.如一年打几次补丁,打哪一个补丁. 在补丁之前,需要进行补丁分析,一份比较完善补丁分析,往往能帮助企业未雨绸缪,提前将可能引发的问题先解决掉,保证生产的稳定和安全 ...
 - ②---Java开发工具Eclipse安装配置
			
Java开发工具Eclipse安装及配置 以下将为大家介绍Java开发工具Eclipse安装及配置. 一.下载Eclipse安装文件 正所谓工欲善其事必先利其器,我们在开发java语言过程中同样需要依 ...
 - mybatis 参数为list时,校验list是否为空, mybatis ${}与#{}的区别
			
一.参数list时,先判断是否为空,否则会报错. 二.mybatis ${}与#{}的区别 简单来说#{} 解析的是占位符?可以防止SQL注入, 比如打印出来的语句 select * from tab ...
 - P3372 【模板】线段树 1
			
题目描述 如题,已知一个数列,你需要进行下面两种操作: 1.将某区间每一个数加上x 2.求出某区间每一个数的和 输入输出格式 输入格式: 第一行包含两个整数N.M,分别表示该数列数字的个数和操作的总个 ...
 - python中numpy.pad简单填充0用法
			
# -*- coding: utf-8 -*-"""Created on Sun Apr 28 22:07:02 2019 @author: jiangshan" ...