2015年上海现场赛重现 (A几何, K暴力搜索)
A:
题目链接 :https://vjudge.net/contest/250823#problem/A
参考 : https://www.cnblogs.com/helenawang/p/5465481.html
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std; const double eps = 1e-; int cmp(double x){
return x < -eps ? - : (x>eps);
} double pow2(double x){
return x * x;
} double mySqrt(double x){
return sqrt(max((double), x));
} struct Vec
{
double x, y;
Vec(){}
Vec(double xx, double yy):x(xx), y(yy){} Vec& operator=(const Vec& v){
x = v.x;
y = v.y;
return *this;
} double norm(){
return sqrt(pow2(x) + pow2(y));
}
//返回单位向量
Vec unit(){
return Vec(x, y) / norm();
}
//判等
friend bool operator==(const Vec& v1, const Vec& v2){
return cmp(v1.x - v2.x)== && cmp(v1.y - v2.y)==;
} //+, -, 数乘
friend Vec operator+(const Vec& v1, const Vec& v2){
return Vec(v1.x + v2.x, v1.y + v2.y);
}
friend Vec operator-(const Vec& v1, const Vec& v2){
return Vec(v1.x - v2.x, v1.y - v2.y);
}
friend Vec operator*(const Vec& v, const double c){
return Vec(c*v.x, c*v.y);
}
friend Vec operator*(const double c, const Vec& v){
return Vec(c*v.x, c*v.y);
}
friend Vec operator/(const Vec& v, const double c){
return Vec(v.x/c, v.y/c);
}
}; int T;
int ans;
Vec O, A, V, B, C, B1;
int R; //点乘
double dot(const Vec v1, const Vec v2){
return v1.x*v2.x + v1.y*v2.y;
}
//叉乘的模长
double product(const Vec v1, const Vec v2){
return v1.x*v2.y - v1.y*v2.x;
} //点p到直线v1,v2的投影
Vec project(Vec& v1, Vec& v2, Vec& p){
Vec v = v2 - v1;
return v1 + v * dot(v, p-v1) / dot(v, v);
}
//点p关于直线v1,v2的对称点
Vec mirrorPoint(Vec& v1, Vec& v2, Vec& p){
Vec c = project(v1, v2, p);
//printf("project: %lf, %lf\n", c.x, c.y);
return (double)*c - p;
} //判断点p是否在线段v1,v2上
bool onSeg(Vec& v1, Vec& v2, Vec& p){
if(cmp(product(p-v1, v2-v1))== && cmp(dot(p-v1, p-v2))<=)
return true;
return false;
} bool calc_C(){
//将AC表示为关于t的参数方程
//则与圆的方程联立得到关于t的一元二次方程, a,b,c为一般式的三个系数
double a = pow2(V.x) + pow2(V.y);
double b = *V.x*(A.x - O.x) + *V.y*(A.y - O.y);
double c = pow2(A.x - O.x) + pow2(A.y - O.y) - pow2(R);
double delta = pow2(b) - *a*c;
if(cmp(delta) <= ) return false;
else{
double t1 = (-b - mySqrt(delta))/(*a);
double t2 = (-b + mySqrt(delta))/(*a);
double t;
if(cmp(t1) >= ) t = t1;
if(cmp(t2) >= && t2 < t1) t = t2;//取较小的那个,即为离A近的那个交点
C.x = A.x + V.x*t;
C.y = A.y + V.y*t;
return true; //有交点
}
} int main()
{
freopen("5572.txt", "r", stdin);
scanf("%d", &T);
for(int ca = ; ca <= T; ca++){
scanf("%lf%lf%d", &O.x, &O.y, &R);
scanf("%lf%lf%lf%lf", &A.x, &A.y, &V.x, &V.y);
scanf("%lf%lf", &B.x, &B.y);
if(calc_C()){
if(onSeg(A, C, B)) ans = ;
else{
//printf("has intersection (%lf, %lf)\n", C.x, C.y);
Vec A1 = mirrorPoint(O, C, A);
// printf("A: %lf, %lf\n", A.x, A.y);
// printf("A1: %lf, %lf\n", A1.x, A1.y);
//printf("B1 (%lf, %lf)\n", B1.x, B1.y);
if(A==A1){
Vec u = B - O;
Vec v = C - O;
// printf("OB: %lf %lf\n", u.unit().x, u.unit().y);
// printf("OC: %lf %lf\n", v.unit().x, v.unit().y);
if(u.unit() == v.unit()){
ans = ;
}else ans = ;
}else {
Vec u = B - C;
Vec v = A1 - C;
if(u.unit() == v.unit()){
ans = ;
}
else ans = ;
}
}
}else{//运动方向不变,则AB与V同向才可碰到B
//printf("no intersection\n");
Vec temp = B - A;
if(temp.unit() == V.unit())
ans = ;
else ans = ;
}
printf("Case #%d: %s\n", ca, ans ? "Yes" : "No");
}
return ;
}
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
const double PI = acos(-1.0);
const double eps = 1e-; int sgn(double x)
{
if(fabs(x) <= eps) return ;
if(x < )return -;
else 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.y);
}
Point operator -(const Point &b)const{
return Point(x-b.x, y-b.y);
}
double operator *(const Point &b)const{
return (x*b.x + y*b.y);
}
double operator ^(const Point &b)const{
return (x*b.y - y*b.x);
}
Point operator *(const double &k)const{
return Point(x*k, y*k);
}
Point operator /(const double &k)const{
return Point(x/k, y/k);
}
// 求点绕远点逆时针旋转后的坐标, 角度A是弧度制
void transXY(double A)
{
x = x*cos(A) - y*sin(A);
y = x*sin(A) + y*cos(A);
}
double len(){return hypot(x,y);} // hypot用于求平方和再开方
double len2() {return x*x + y*y;}
// 求两点之间的距离
double distance(Point p){return hypot(x-p.x ,y-p.y );} Point trunc(double r) {
double l = len();
if(!sgn(l)) return *this;
r /= l;
return Point (x*r, y*r);
}
}; struct Line {
Point s,e;
Line(){}
Line(Point _s,Point _e) {
s = _s;e = _e;
}
double length(){ return s.distance(e);}
pair<int,Point> operator &(const Line &b)const {
Point res = s;
if(sgn((s-e)^(b.s-b.e)) == ) {
if(sgn((s-b.e)^(b.s-b.e)) == ) return make_pair(,res);
else return make_pair(,res);
}
double t = ((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
res.x += (e.x-s.x)*t;
res.y += (e.y-s.y)*t;
return make_pair(,res);
}
int relation(Point p) {
int c = sgn((p - s) ^ (e - s));
if(c < ) return ;
else if(c > ) return ;
else return ;
}
double disPointtoline(Point p) { return fabs((p-s)^(e-s))/length();}
double disPointtoseg(Point p) {
if(sgn((p - s) * (e - s)) < || sgn((p - e) * (s - e)) < )
return min(p.distance(s), p.distance(e));
return disPointtoline(p);
}
Point lineprog(Point p) { return s+(((e-s)*((e-s)*(p-s)))/((e-s).len2()));}
Point symmetryPoint(Point p) {
Point q = lineprog(p);
return Point(*q.x-p.x, *q.y-p.y);
}
}; struct Circle {
Point p;
double r;
int relationline(Line v) {
double dst = v.disPointtoline(p);
if(sgn(dst-r) < ) return ;
else if(sgn(dst-r) == ) return ;
return ;
}
int Pointcrossline(Line v, Point &p1, Point &p2) {
if(!(*this).relationline(v)) return ;
Point a = v.lineprog(p); double d = v.disPointtoline(p);
d = sqrt(r*r-d*d);
if(sgn(d) == ) {p1 = a; p2 = a; return ;}
p1 = a + (v.e - v.s).trunc(d);
p2 = a - (v.e - v.s).trunc(d);
return ;
}
int relationseg(Line v) {
double dst = v.disPointtoseg(p);
if(sgn(dst - r) < ) return ;
else if(sgn(dst - r) == ) return ;
else return ;
}
}; int main() {
int t;
scanf("%d", &t);
Circle c;
Point a, v, b;
for(int o = ; o <= t; o++) {
printf("Case #%d: ", o);
scanf("%lf %lf %lf", &c.p.x, &c.p.y, &c.r);
scanf("%lf %lf %lf %lf", &a.x, &a.y, &v.x, &v.y);
scanf("%lf %lf", &b.x, &b.y);
Line ab = Line(a, b);
Point av = a + v;
Line l = Line(a, av);
int flag = ;
if(l.relation(b) == && sgn((b-a)*(av-a)) > && c.relationseg(ab) <= ) flag = ;
else {
Point p1, p2;
if(c.Pointcrossline(l, p1, p2) == ) {
Point m = sgn(a.distance(p1) - a.distance(p2)) < ? p1 : p2;
Line f(c.p, m);
Point q = f.symmetryPoint(a);
Line tmp(m, q);
if(tmp.relation(b) == && sgn(((b-m)*(q-m)))>) flag = ;
}
}
puts(flag?"Yes":"No");
}
return ;
}
K:
题目链接 : https://vjudge.net/contest/250823#problem/K
输出没有加Case狂wa, 坑爹啊;
#include<iostream>
#include<cstdio>
#include<vector> using namespace std;
#define ll long long
const int maxn = ; ll cal(ll a) // 计算平方
{
return a*a;
} vector<int > v; // 用于存每一个子序列的长度 int main()
{
int t;
cin >> t;
int j =;
while(j++ < t)
{
string s;
cin >> s;
v.clear(); // 清空
v.push_back(); // 在数组首加入0
int last = s[];
ll ans = , cnt = ;
for(int i = ; i < s.size(); i++) // 从第二个字符开始遍历
{
if(s[i] == s[i-]) // 相等则长度加一
{
cnt++;
}
else {
ans += cal(cnt); // 加上该子串对结果的贡献,先不考虑更改字符
v.push_back(cnt); // 如果不等则把cnt 记录到数组
cnt =;
last = s[i];
} }
v.push_back(cnt);
ans += cal(cnt);
// cout << ans << endl;
v.push_back(); // 在数组尾加入0
// for(int i = 0; i < v.size(); i++)
// cout << v[i] << " ";
ll ans2 = ans;
for(int i = ; i < v.size()-; i++)
{
ll tmp, tmp2;
if(v[i] == )
{
tmp = ans+cal(v[i-]+v[i+]+)--cal(v[i-])-cal(v[i+]);
ans2 = max(ans2, tmp);
}
else
{
tmp2 = ans+cal(v[i-]+)+cal(v[i]-)-cal(v[i])-cal(v[i-]);
ans2 = max(ans2, tmp2);
}
}
printf("Case #%d: %lld\n", j, ans2);
} }
2015年上海现场赛重现 (A几何, K暴力搜索)的更多相关文章
- 2018 ICPC上海大都会赛重现赛 D Thinking-Bear magic (几何)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 D Thinking-Bear magic (几何) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it
链接:https://www.nowcoder.com/acm/contest/163/F 来源:牛客网 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it 时间限制:C ...
- 2018 ACMICPC上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 H - A Simple Problem with Integers (线段树,循环节) 链接:https://ac.nowcoder.co ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 F Color it (扫描线) 链接:https://ac.nowcoder.com/acm/contest/163/F来源:牛客网 时间 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP)
2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位DP) 链接:https://ac.nowcoder.com/acm/contest/163/ ...
- 2018ICPC青岛现场赛 重现训练
先贴代码,以及简要题解. 和一个队友下午双排打了一下,队友光速签到,我签的J被嫌弃写得慢以及演员...然后我秒出了E了思路然而难以置信这么简单的思路当时才过了十几个,于是发现D.F不是太好做.最后交了 ...
- ACM 2015年上海区域赛A题 HDU 5572An Easy Physics Problem
题意: 光滑平面,一个刚性小球,一个固定的刚性圆柱体 ,给定圆柱体圆心坐标,半径 ,小球起点坐标,起始运动方向(向量) ,终点坐标 ,问能否到达终点,小球运动中如果碰到圆柱体会反射. 学到了向量模板, ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 J Beautiful Numbers (数位dp)
题目链接:https://ac.nowcoder.com/acm/contest/163/J 题目大意:给定一个数N,求区间[1,N]中满足可以整除它各个数位之和的数的个数.(1 ≤ N ≤ 1012 ...
- 2018 ACM 国际大学生程序设计竞赛上海大都会赛重现赛 A,D
A链接:https://www.nowcoder.com/acm/contest/163/A Fruit Ninja is a juicy action game enjoyed by million ...
随机推荐
- mysql的event(事件)用法详解
SELECT * FROM mysql.event;SET GLOBAL event_scheduler = 1; -- 开启定时器 0:off 1:on SHOW VARIABLES LIKE 'e ...
- 前端性能优化 —— 添加Expires头
简要:添加Expires头能有效的利用浏览器的缓存能力来改善页面的性能,能在后续的页面中有效避免很多不必要的Http请求,WEB服务器使用Expires头来告诉Web客户端它可以使用一个组件的当前副本 ...
- NOIP-玩具谜题
题目描述 小南有一套可爱的玩具小人,它们各有不同的职业. 有一天,这些玩具小人把小南的眼镜藏了起来.小南发现玩具小人们围成了一个圈,它们有的面朝圈内,有的面朝圈外,如下图: 这时 `singer` 告 ...
- JS_高程8.BOM window对象(1)
1.全局作用域 var age = 14; window.coloer = "pink"; console.log(delete window.age);//false 使用var ...
- 《Head First JavaScript》 学习笔记
<scipt type="text/javascript" src"cookie.js"> </script> //脚本署名方法 &l ...
- 配置ssh框架启动tomcat服务器报异常Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
在Spring中配置jdbc时,引用的是dbcp.jar包,在db.properties配置文件中,使用了之前的properties配置文件的用户名username(MySql用户名) 然后在启动服务 ...
- kubenetes master重启以后,服务异常排查
k8s集群环境:三台机器,一台master,三个node(每台都安装node服务) 问题藐视:重启的时候,发现master的服务都能正常启动,但是就是不好使,看/var/log/message日志也没 ...
- Spring Cloud 学习记录
Spring Cloud中文网 拜托!面试不要再问我Spring Cloud底层原理 SpringCloud简介与5大常用组件 Spring Cloud在国内中小型公司能用起来吗?
- 生成N位数字随机数
//生成N位的随机数 全数字 private string GetRandom(int len) { string k = ""; Random rand = new Random ...
- Kafka: Exactly-once Semantics
https://www.confluent.io/blog/enabling-exactly-kafka-streams/ https://cwiki.apache.org/confluence/di ...