2017 ACM/ICPC Asia Regional Qingdao Online解题报告(部分)
题意:
给出四个点的坐标(每个点的坐标值小于等于1,000,000,000,000),问最后一个点是否在前三个点组成的三角形的外接圆内,是输出Accept,否输出Rejected
解题思路:
题意很好理解,就是判断一个点是否在一个圆内,或者说一个点到圆心的距离是否大于半径,关键是大整数和精度问题,题解中给出了java的解法。
设x0,y0为圆心,有圆心到三个顶点的距离相等,列出如下两个式子:
(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0) = (x2-x0)*(x2-x0)+(y2-y0)*(y2-y0).
(x2-x0)*(x2-x0)+(y2-y0)*(y2-y0) = (x3-x0)*(x3-x0)+(y3-y0)*(y3-y0).
化简可得:
2(x2-x1)x0 + 2(y2-y1)y0 = x2^2 + y2^2 - x1^2 - y1^2.
2(x3-x2)x0 + 2(y3-y2)y0 = x3^2 + y3^2 - x2^2 - y2^2.
令a1 = 2*(x2-x1);
b1 = 2*(y2-y1);
c1 = x2^2 + y2^2 - x1^2 - y1^2;
a2 = 2*(x3-x2);
b2 = 2*(y3-y2);
c2 = x3^2 + y3^2 - x2^2 - y2^2;
则
a1*x0 + b1*y0 = c1;
a2*x0 + b2*y0 = c2;
根据克莱姆法则(具体参见记法2)可得
x0 = (c1*b2 - b1*c2)/(a1*b2 - b1*a2);
y0 = (a1*c2 - c1*a2)/(a1*b2 - b1*a2);
由两点间距离公式得
r = (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
d = (x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);(x-x0)*(x-x0)+(y-y0)*(y-y0);(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0)
由于涉及到大整数和高精度,使用Java中的BidDecimal代码如下:
import java.math.BigDecimal;
import java.util.Scanner; public class Main { public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while(T-- > 0) {
BigDecimal x1 = in.nextBigDecimal();
BigDecimal y1 = in.nextBigDecimal();
BigDecimal x2 = in.nextBigDecimal();
BigDecimal y2 = in.nextBigDecimal();
BigDecimal x3 = in.nextBigDecimal();
BigDecimal y3 = in.nextBigDecimal();
BigDecimal x = in.nextBigDecimal();
BigDecimal y = in.nextBigDecimal(); BigDecimal a1 = x2.subtract(x1).multiply(BigDecimal.valueOf(2));
BigDecimal b1 = y2.subtract(y1).multiply(BigDecimal.valueOf(2));
BigDecimal c1 = x2.pow(2).add(y2.pow(2)).subtract(x1.pow(2)).subtract(y1.pow(2)); BigDecimal a2 = x3.subtract(x2).multiply(BigDecimal.valueOf(2));
BigDecimal b2 = y3.subtract(y2).multiply(BigDecimal.valueOf(2));
BigDecimal c2 = x3.pow(2).add(y3.pow(2)).subtract(x2.pow(2)).subtract(y2.pow(2)); BigDecimal x0 = b2.multiply(c1).subtract(b1.multiply(c2)).divide(a1.multiply(b2).subtract(b1.multiply(a2)));
BigDecimal y0 = a1.multiply(c2).subtract(c1.multiply(a2)).divide(a1.multiply(b2).subtract(b1.multiply(a2))); BigDecimal r = x1.subtract(x0).pow(2).add(y1.subtract(y0).pow(2));
BigDecimal d = x.subtract(x0).pow(2).add(y.subtract(y0).pow(2));
if(1 == d.compareTo(r))
System.out.println("Accepted");
else
System.out.println("Rejected");
}
} }
HDU 6208 The Dominator of Strings
题意:
给出n个串,问是否存在一个串能够包含这n个串。
解题思路:
AC自动机的模板题,注意输入字符串的数组开大一点就行了。
#include <cstdio>
#include <cstring> const int K = ;
const int maxn = + ;
struct Node {
Node *ch[K], *fail;
int mc;
void clear(){
memset(this, , sizeof(Node));
}
}; Node *que[maxn*];
struct AC {
Node nodes[maxn], *root, *sroot, *cur;
Node* newNode() {
cur->clear();
return cur++;
}
void clear() {
cur = nodes;
sroot = newNode();
root = newNode();
root->fail = sroot;
for(int i = ; i < K; i++) {
sroot->ch[i] = root;
}
sroot->mc = -;
}
void insert(char *s) {
Node* t = root;
for(; *s; s++) {
int x = *s - 'a';
if(t->ch[x] == NULL)
t->ch[x] = newNode();
t=t->ch[x];
}
t->mc++;
}
void build() {
int p = , q = ;
que[q++] = root;
while(p != q) {
Node *t = que[p++];
for(int i = ; i < K; i++) {
if(t->ch[i]) {
t->ch[i]->fail = t->fail->ch[i];
que[q++] = t->ch[i];
}
else
t->ch[i] = t->fail->ch[i];
}
}
}
int run(char *s) {
int ans = ;
Node* t = root;
for(; *s; s++) {
int x = *s - 'a';
t = t->ch[x];
for(Node* u = t; u->mc != -; u = u->fail) {
ans += u->mc;
u->mc = -;
}
}
return ans;
}
}ac;
int n;
char s[], t[];
int main()
{
int T;
scanf("%d", &T);
while(T--) {
scanf("%d", &n);
ac.clear();
int maxl = ;
memset(t, , sizeof(t));
for(int i = ; i < n; i++) {
scanf(" %s", s);
int len = strlen(s);
if(len > maxl) {
maxl = len;
strcpy(t, s);
}
ac.insert(s);
}
ac.build(); if(ac.run(t) == n)
puts(t);
else
puts("No");
}
return ;
}
HDU 6216 A Cubic number and A Cubic Number
题意:
判断一个质数p,是否是两个立方数之差
解题思路:
由题(x^3 - y^3) = p
即(x - y) * (x^2 - 2*x*y + y^2) = p
由于p是质数,所以(x - y) = 1,即x = y + 1,代入原式得
3 * y * y + 3 * y + 1 = p
枚举10^6以内的y,对于每一个p搜索是否存在即可。
#include <cstdio>
typedef long long ll;
const ll maxn = 1e6 + ;
ll ls[maxn]; int main()
{
int T;
ll p;
for(ll i = ; i < maxn; i++) {
ls[i] = * i * i + * i + ;
}
scanf("%d", &T);
while(T--) {
scanf("%lld", &p);
bool f = ;
int le = -, ri = maxn;
while(ri - le > ) {
int mid = (ri + le) >> ;
if(p == ls[mid]) {
f = ;
break;
} else if(p > ls[mid])
le = mid;
else
ri = mid;
}
if(f)
puts("YES");
else
puts("NO");
}
return ;
}
题意:
前提是女的比男的大,给出生肖,问两人的最小年龄差是多少
#include <cstdio>
#include <map>
#include <cstring>
#include <string>
#include <iostream>
using namespace std; const string ls[] = {"rat", "ox", "tiger", "rabbit", "dragon", "snake", "horse", "sheep",
"monkey", "rooster", "dog", "pig"}; int main()
{
int T;
map<string, int> mp;
for(int i = ; i < ; i++) {
mp[ls[i]] = i + ;
}
string a, b;
cin >> T;
while(T--) {
cin >> a >> b;
int c = mp[a];
int d = mp[b];
int ans = d - c; if(ans <= )
ans += ;
cout << ans <<endl;
}
return ;
}
2017 ACM/ICPC Asia Regional Qingdao Online解题报告(部分)的更多相关文章
- 2017 ACM/ICPC Asia Regional Qingdao Online
Apple Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submi ...
- HDU - 6215 2017 ACM/ICPC Asia Regional Qingdao Online J - Brute Force Sorting
Brute Force Sorting Time Limit: 1 Sec Memory Limit: 128 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...
- 2017 ACM/ICPC Asia Regional Qingdao Online 记录
题目链接 Qingdao Problem C AC自动机还不会,暂时暴力水过. #include <bits/stdc++.h> using namespace std; #define ...
- 2017 ACM/ICPC Asia Regional Qingdao Online Solution
A : Apple 题意:给出三个点,以及另一个点,求最后一个点是否在三个点的外接圆里面,如果在或者在边界上,输出“Rejected”,否则输出"Accepted" 思路:先求一个 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online - 1011 A Cubic number and A Cubic Number
2017-09-17 17:12:11 writer:pprp 找规律,质数只有是两个相邻的立方数的差才能形成,公式就是3 * n * (n + 1) +1, 判断读入的数是不是满足 这次依然只是做了 ...
- 2017 ACM/ICPC Asia Regional Qingdao Online - 1008 Chinese Zodiac
2017-09-17 13:28:04 writer:pprp 签到题:1008 Chinese Zodiac #include <iostream> #include <strin ...
- 2017 ACM/ICPC Asia Regional Qingdao Online 1003 The Dominator of Strings hdu 6208
The Dominator of Strings Time Limit: 3000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java ...
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
随机推荐
- 2019.03.04 bzoj5308: [Zjoi2018]胖(二分答案+st表)
传送门 想题5分钟调题两小时系列 其实还是我tcl 读完题之后自然会知道一个关键点能够更新的点是一段连续的区间,于是我们对于每个点能到的左右区间二分答案,用ststst表维护一下查询即可. 代码: # ...
- Linux学习---GCC编译过程
(一)GCC编译过程 预处理 cpp -o a.i a.c //生成预处理文件 等同于[gcc -E] //预处理为将宏定义(#define)等进行替换. 编译 /user/lib/gcc/i ...
- IntelliJ IDEA 2017版 spring-boot2.0.2 搭建 JPA springboot DataSource JPA sort排序方法使用方式, 添加关联表的 order by
1.sort可以直接添加在命名格式的字段中 List<BomMain> findAllByDeleted(Integer deleted, Sort sort); 2.可以作为pageab ...
- python基本数据类型之字符串(五)
python基本数据类型之字符串(五) 遍历与查找 python中的字符串属于可迭代对象,通过一些方法可以遍历字符串中的每一个字符.而查找的方法主要有两个:find与index. 1.字符串的遍历 字 ...
- dom4j 通过 org.dom4j.XPath 设置命名空间来支持 带namespace 的 xpath
测试文件 test.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http:/ ...
- VDD,VCC,VSS,VEE,VDDA,VSSA,
VDD是主供电电源,也是IO口输出电平的输入电源.VDDA(A表示模拟)是模拟电源,当使用到模拟信号的时候,比如AD(模数)或者DA(数模)的时候,系统会使用VDDA的电压作为参考电压来.不要求精准使 ...
- PHP 文件处理----fopen(),fclose(),feof(),fgets(),fgetc()
fopen() 函数用于在 PHP 中打开文件. 打开文件 fopen() 函数用于在 PHP 中打开文件. 此函数的第一个参数含有要打开的文件的名称,第二个参数规定了使用哪种模式来打开文件: < ...
- JavaScript ~~ECMAScript
一.JavaScript 简介 HTML:从语义的角度,描述页面结构 CSS:从审美的角度,描述样式(美化页面) JavaScript:从交互的角度,描述行为(提升用户体验) 2.JavaScript ...
- Android Studio在项目中添加assets资源目录
第一步: 切换到"Project"视图,找到app --> src --> main目录 第二步: 右键点击main目录,New --> Directory -- ...
- 微信小程序如何调用API实现数据请求-wx.request()
前言 微信小程序不存在ajax,那么它是如何实现数据请求功能的呢?在微信中提供了API的调用wx.request(OBJECT),这个是很不错的.下面就讲一下如何请求数据,简单到不行. wx.requ ...