Gym 101334A Area 51 数学
大致题意:
给出n个建筑的二维坐标,每个建筑名称为一个字母,不同坐标的建筑可以有同一名称,并保证这些坐标都是在y轴上半轴。给出一串建筑名称的字符串,在X轴上找出一个或多个区间,使Nick在这个区间上从左往右观看,看到的建筑顺序与给出的字符串相符合。
分析:
建筑物的数量最多100,那么我们可以先求出任意两点的连线与X轴的交点,每两个相邻的交点间的开区间看到的顺序是相同的。那么我们枚举所有区间即可。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define eps 1e-9
using namespace std; const int maxn=100+5;
const int INF=1e5;
int n;
char s[maxn];
double cosA[maxn];
double p[maxn*maxn];
double ans[maxn*maxn]; struct Facility
{
char c;
int x;
int y;
}fac[maxn]; struct Angle
{
char c;
double cosA;
}ang[maxn]; bool cmp(Angle a,Angle b)
{
return a.cosA<b.cosA;
} bool judge(double o)
{
for(int i=0;i<n;i++)
{
ang[i].c=fac[i].c;
ang[i].cosA=(fac[i].x-o)/sqrt(fac[i].y*fac[i].y+(fac[i].x-o)*(fac[i].x-o)); //算区间中点与建筑的连线与X轴正方向的夹角的余弦值
}
sort(ang,ang+n,cmp);
for(int i=0;i<n;i++)
if(ang[i].c!=s[i])
return false;
return true;
} int main()
{
// freopen("in.txt","r",stdin);
// freopen("area.in","r",stdin);
// freopen("area.out","w",stdout);
while(~scanf("%d",&n))
{
getchar();
scanf("%s",s);
for(int i=0;i<n;i++)
{
getchar();
scanf("%c%d%d",&fac[i].c,&fac[i].x,&fac[i].y);
}
p[0]=-INF;
int cnt=1;
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(fac[i].y==fac[j].y) continue;
p[cnt++]=1.0*(fac[j].x*fac[i].y-fac[i].x*fac[j].y)/(fac[i].y-fac[j].y);
}
}
p[cnt++]=INF;
sort(p,p+cnt);
int cnt2=0;
for(int i=0;i<cnt-1;i++)
{
if(p[i+1]-p[i]<eps) continue;
if(judge((p[i]+p[i+1])/2)) //去区间中点来判断此区间是否合法
{
ans[cnt2++]=p[i];
ans[cnt2++]=p[i+1];
}
}
printf("%d\n",cnt2/2);
if(cnt2==0) continue;
if(fabs(ans[0]-p[0])<eps)
printf("%c ",'*');
else
printf("%.7f ",ans[0]);
for(int i=1;i<cnt2-1;i++)
printf("%.7f ",ans[i]);
if(fabs(ans[cnt2-1]-p[cnt-1])<eps)
printf("%c\n",'*');
else
printf("%.7f\n",ans[cnt2-1]);
}
return 0;
}
Gym 101334A Area 51 数学的更多相关文章
- HDU 1798 Tell me the area (数学)
题目链接 Problem Description There are two circles in the plane (shown in the below picture), there ...
- CF Gym 100187D Holidays (数学,递推)
题意:给n个元素,从n中选两个非空集合A和B.问有多少中选法? 递推: dp[n]表示元素个数为n的方案数,对于新来的一个元素,要么加入集合,要么不加入集合自成一个集合.加入集合有三种选择,A,B,E ...
- 五、Pandas玩转数据
Series的简单运算 import numpy as np import pandas as pd s1=pd.Series([1,2,3],index=['A','B','C']) print(s ...
- 看StackOverflow如何用25台服务器撑起5.6亿的月PV(微软的架构)
问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 ...
- StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's All About Performance
http://highscalability.com/blog/2014/7/21/stackoverflow-update-560m-pageviews-a-month-25-servers-and ...
- 看StackOverflow如何用25台服务器撑起5.6亿的月PV
问答社区网络 StackExchange 由 100 多个网站构成,其中包括了 Alexa 排名第 54 的 StackOverflow.StackExchang 有 400 万用户,每月 5.6 亿 ...
- [收藏]NET技术+25台服务器怎样支撑世界第54大网站
.NET技术+25台服务器怎样支撑世界第54大网站 英文原文:StackOverflow Update: 560M Pageviews A Month, 25 Servers, And It's ...
- win10 ctrl + 空格 热键取消
关键:添加English,并上移到第一,即开机默认即可.Win8+不用修改注册表的,只有win7里才可能需要修改注册表. http://superuser.com/questions/327479/c ...
- .NET技术+25台服务器怎样支撑世界第54大网站(转)
[编者按]StackOverflow是一个IT技术问答网站,用户可以在网站上 提交和回答问题.当下的StackOverflow已拥有400万个用户,4000万个回答,月PV5.6亿,世界排行第54.然 ...
随机推荐
- Hive 配置项详解
hive.ddl.output.format: hive的ddl语句的输出格式, 默认是text,纯文本,还有json格式,这个是0.90以后才出的新配置: hive.exec.script.wrap ...
- mysql8 安装配置教程
第一步 下载安装包 MySQL 是甲骨文(Oracle)公司产品,可以到官网上下载 MySQL: 官网下载地址:https://dev.mysql.com/downloads/mysql/ 如果嫌弃官 ...
- 11.13 ethtool:查询网卡参数
ethtool命令用于查询或设置网卡参数. ethtool [devname] [root@linuxprobe ~]# ethtool eth0 Settings for eth0: Suppor ...
- 原生基础js脚本实现--在线答题系统
全部代码在最下面----需要的直接往下翻 html方面的代码 : 正确的答案 value=s <!DOCTYPE html> <html lang="en"&g ...
- kylin的rowkey优化之调整rowkey顺序
在以hbase为存储的cuboid中,会有很多计算好的数据行,这每个行的key都是由维度值按顺序生成的rowkey 而这个顺序,在我们做cube设计的时候是可以调整的. 具体调整路径是:cube de ...
- 解决maven依赖冲突问题
解决maven依赖冲突问题 1.idea 安装maven helper插件 2.打开pom.xml文件 底部多出一个Dependency Analyzer选项 点开这个选项 找到冲突,点击右键,选择E ...
- css——圣杯布局
圣杯布局要求 header和footer各自占领屏幕所有宽度,高度固定 中间dontainer部分为左中右三栏式布局 三栏布局中左右两侧宽度固定,中间部分自动填充 实现方式 1.浮动 先定义heade ...
- 目标检测中的anchor-based 和anchor free
目标检测中的anchor-based 和anchor free 1. anchor-free 和 anchor-based 区别 深度学习目标检测通常都被建模成对一些候选区域进行分类和回归的问题.在 ...
- deeplearning算法优化原理
deeplearning算法优化原理目录· 量化原理介绍 · 剪裁原理介绍 · 蒸馏原理介绍 · 轻量级模型结构搜索原理介绍 1. Quantization Aware Training量化介绍1.1 ...
- 微调BERT:序列级和令牌级应用程序
微调BERT:序列级和令牌级应用程序 Fine-Tuning BERT for Sequence-Level and Token-Level Applications 为自然语言处理应用程序设计了不同 ...