HDU 6206 Apple

题意:

给出四个点的坐标(每个点的坐标值小于等于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 ;
}

HDU 6213 Chinese Zodiac

题意:

前提是女的比男的大,给出生肖,问两人的最小年龄差是多少

 #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解题报告(部分)的更多相关文章

  1. 2017 ACM/ICPC Asia Regional Qingdao Online

    Apple Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submi ...

  2. 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 ...

  3. 2017 ACM/ICPC Asia Regional Qingdao Online 记录

    题目链接  Qingdao Problem C AC自动机还不会,暂时暴力水过. #include <bits/stdc++.h> using namespace std; #define ...

  4. 2017 ACM/ICPC Asia Regional Qingdao Online Solution

    A : Apple 题意:给出三个点,以及另一个点,求最后一个点是否在三个点的外接圆里面,如果在或者在边界上,输出“Rejected”,否则输出"Accepted" 思路:先求一个 ...

  5. 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, 判断读入的数是不是满足 这次依然只是做了 ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. ABP Quartz 作业调度第三篇

    1.第一步安装Abp.Quartz ,把他安装到核心层 核心模块添加对quarz的依赖, 领域层创建firstjob类 public class FirstJob : JobBase, ITransi ...

  2. java多线程系列12 ConcurrentHashMap CopyOnWriteArrayList 简介

    我们知道 ,hashmap 和 arraylist 是线程不安全的 在多线程环境下有数据安全问题, 当然 我们可以通过Collections的一些方法把他们变成线程安全的, Collections.s ...

  3. @Scheduler与cron

  4. ABP框架系列之十七:(Data-Filters-数据过滤)

    Introduction It's common to use the soft-deletepattern which is used to not delete an entity from da ...

  5. CodeCraft-19 and Codeforces Round #537 (Div. 2) E 虚树 + 树形dp(新坑)

    https://codeforces.com/contest/1111/problem/E 题意 一颗有n个点的树,有q个询问,每次从树挑出k个点,问将这k个点分成m组,需要保证在同一组中不存在一个点 ...

  6. LwIP协议栈接口

    协议栈api函数 1.netconn_new      //UDP    TCP struct netconn*netconn_new(enum netconn_type t) 为新连接申请一个连接结 ...

  7. ubuntu 14.04下搭建esp32开发环境

    esp32是乐鑫出品的一款集成了wifi和蓝牙的集成模块,板上自带两个哈佛结构的Xtensa LX6 CPU双核处理器,本文主要讲解如何在linux下搭建其编译开发环境. 首先ctrl+alt+t打开 ...

  8. 《mysql必知必会》学习_第14章_20180806_欢

    第14章:使用子查询. 子查询是镶嵌在其他查询里面,相当其他的select查询的条件来. P91 select order_num from where prod_id='tnt2';   #检索条件 ...

  9. MFC 多窗口通信时,使用RadioButton和Button时冲突问题

    最近项目需要我们实现在两个窗口间进行通信,其中有个小功能如图所示: 当我点击GDIProgram中的Button1时,会更新Dialog的Radio1和Radio2的状态. Dialog中的Radio ...

  10. Runtime之成员变量&属性&关联对象

    上篇介绍了Runtime类和对象的相关知识点,在4.5和4.6小节,也介绍了成员变量和属性的一些方法应用.本篇将讨论实现细节的相关内容. 在讨论之前,我们先来介绍一个很冷僻但又很有用的一个关键字:@e ...