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.记一记,要不然枉费我写这么久…… 自己还是代码能力太菜了,校 ...
随机推荐
- Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException的解决方案
Call to localhost/127.0.0.1:9000 failed on connection exception:java.net.ConnectException的解决方案 作者:凯鲁 ...
- Spring容器技术内幕之BeanWrapper类介绍
引言 org.springframework.beans.BeanWrapper是Spring框架中重要的组件类.BeanWrapper相当于一个代理器,Spring委托BeanWrapperwanc ...
- cookie保存登录的用户名和密码
用cookie保存登录的用户名和密码,当用户访问网站的时候,获取cookie的用户名和密码,通过用 用cookie保存登录的用户名和密码,当用户访问网站的时候,获取cookie的用户名和密码,通过用户 ...
- React项目中那些奇怪的写法
1.在一个React组件里看到一个奇怪的写法: const {matchs} = this.props.matchs; 原来,是解构赋值,虽然听说过,但是看起来有点奇怪 下面做个实验: <scr ...
- flex布局快速成型(原创)
最近我根据一个UI设计,耗时3h快速实现较复杂页面布局,如上图.根据这份UI设计图,实现代码如下,暂不考虑具体细节,先以成型为主: <!DOCTYPE html> <html> ...
- 配置DispatcherServlet应该写/还是/*
相亲怎么做 web应用需要放在Tomcat容器中才能启动,Tomcat容器内有一个默认的web.xml文件,在自己项目中配置的XML文件都是继承自Tomcat中的全局XML文件并重写其中相应配置,这种 ...
- (三)JavaScript 语法
字符串(String)字面量 可以使用单引号或双引号: "John Doe" 'John Doe' 数组(Array)字面量 定义一个数组: [40, 100, 1, 5, 25, ...
- docker 8 docker的镜像命令
先回顾一下容器.存储.镜像三者之间的关系. 我们知道docker的logo是一条大鲸鱼背上驮着集装箱.那我们对应到docker如下: 1)蓝色的大海里面------->宿主机系统比如我笔记本wi ...
- DAO层基础设计原理
在实际的开发中有一种项目的程序组织架构方案叫做MVC模式,按照程序 的功能将他们分成三个层,如下图 Modle层(模型层).View层(显示层).Controller层(控制层). Modle层:可以 ...
- <网络编程>套接字介绍
1.端口:IANA(Internet Assigned Numbers Authority)维护着一个端口号分配状况的清单. 众所周知的端口(0-1023):由IANA分配和控制,可能的话,相同的端口 ...