题目描述:

Professor Parinita Pratim Das, a brilliant
Mathematician of this era, dreams of winning
the Fields Medal someday for her
patented Spirals that are custom made to
hypnotize Engineers. To show that her
ideas actually work she wants to paint her
office room walls with various shapes of
spirals.
Her method of drawing spirals goes
something like this:
• She picks a spiral (in polar coordinates)
of the form, r = aθ
• Then she adds n rays shooting out
from the origin — the i-th ray being
of the form θ = bi (positive or
counter clockwise angle with the x
axis)
• Finally she marks out m points
(rj , θj ) — if a point is in a bounded
region then that entire region will be painted black

Professor Das computes r in meters and knows that she needs 1 liter of black paint for per 10 meter2
area on the wall. She needs your help to calculate how much paint she needs to buy.
Input
The input for this problem starts with S (S ≤ 100), the number of spirals Professor Das wants to paint.
Each of the hypnotic spirals is described in three lines. The first line of a spiral’s description gives
a floating point number giving the value of a (0 < a < 10).
The next line starts with the value of integer n (0 ≤ n ≤ 10). Then follows n floating-point number
θi
, 0 ≤ θi < 2π, each giving the θ values for the n rays. You can assume that all the θi values are
unique (Differs by at least 0.01).
The last line of spiral’s description start with the value of m (0 ≤ m ≤ 1000). The next m pairs
of floating-point numbers, (rj, θj ), 0 < rj < 100, 0 ≤ θj < 2π, in the line gives the coordinates of the
points which Professor Das mark out for painting. You can assume that none of the points will be on
the spiral’s curve or on any of the rays. Note that all the θ values in the input will be given in radians.
Output
For each test case print the spiral’s number (in the format shown in the sample output). Then print the
amount of black paint (in liters, rounded to 4 digits after the decimal point) needed to paint that spiral
on Professor Das’ wall. If the region to be painted is unbounded, print a ‘-1’ instead. The amount of
black paint will be such that an error of 5 × 10−8 will not change the printed output.

题解:

大致思路一下就有, 就是算出来th属于的上一个k和下一个k,然后再看弧度在哪两个射线之间. 但是有细节要注意:
1.看弧度在哪两个之间,涉及到转一圈的问题,我们设置一个-角度(代码中没设但是特判了)和一个大于2*Pi的角度,这样好找,然后k就能统一找了.
2.我们需要用mp来判重复,但是记者一个负角度和一个大于2*Pi的是一样的,需要特殊处理
3.本题中的特殊情况:(1)在第一圈并且有附角的时候,负角度没用,我们应该从0开始积分(2)在最内一圈,不用减去里面的圈,因为没有.(3)在最内一圈和外面一圈的交界处,有的用减去里面的圈,有的不用,分段计算. 总结起来就是,最内圈先是从0开始,并且本身不是环状,影响了这三个

重点:

计算几何的简单题,要有(1)技巧(2)特殊情况的考虑

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <algorithm>using namespace std;const int maxn = 1000 + 10;
const double Pi = acos(-1.0);
double alp[maxn], r, th, a;
int alpn, n;
map<int, map<int, int> > mp; double f(double aa, double bb) {return a * a / 6 * (bb * bb * bb - aa * aa * aa);
}int getk(double r, double th) {//printf("222 %f %f %f\n", r, th, a);int low = 0, high = 1e9;while(low  <=  high) {int mid = (low + high) / 2;if(a * (th + mid * 2 * Pi) > r)high = mid - 1;elselow = mid + 1;}if(a * (th + low * 2 * Pi) <= r)while(1);/* for(int i = 0; ;i++) {printf("333  %f\n", a * (th + i * 2 * Pi));if(a * (th + i * 2 * Pi) > r) {printf("111  %lf\n",  i - 1);return i - 1;}}*///    printf("****  %f\n", high - 1);return high;
}
void solve() {mp.clear();double ans = 0;scanf("%d", &alpn);for(int i = 0; i < alpn; i++) {scanf("%lf", &alp[i]);}if(alpn == 0) {scanf("%d", &n);for(int i = 0; i < n; i++) {double a, b;scanf("%lf%lf", &a, &b);}printf("-1\n");return ;}sort(alp, alp + alpn);alp[alpn] = alp[0] + 2 * Pi;alpn++;scanf("%d", &n);for(int i = 0; i < n; i++) {scanf("%lf %lf", &r, &th);int key;for(int j = 0;;j++) {if(alp[j] > th) {key = j;break;}}double a1, a2;a2 = alp[key];if(key != 0)a1 = alp[key - 1];else {a1 = alp[alpn - 2] - 2 * Pi;//printf("adfdsfs\n");// swap(a1, a2);}//            a2 = alp[alpn - 2] - 2 * Pi;int k = getk(r, th);//printf("111   %d\n", k);if(key == alpn - 1) {k++;key = 0;a1 -= 2 * Pi;a2 -= 2 * Pi;}if(mp[key][k])continue;else {mp[key][k] = 1;if(k == -1 && a1 < 0) {ans += f(0, a2);//printf("fadsfasd");}else {if(k == -1) {ans += f(a1 + (k + 1) * 2 * Pi, a2 + (k + 1) * 2 * Pi);}else {if(k == 0 && a1 < 0) {ans += f((k + 1) * 2 * Pi, a2 + (k + 1) * 2 * Pi);ans -= f(k * 2 * Pi, a2 + k * 2 * Pi);ans += f(a1 + (k + 1) * 2 * Pi, (k + 1) * 2 * Pi);}else {ans += f(a1 + (k + 1) * 2 * Pi, a2 + (k + 1) * 2 * Pi);ans -= f(a1 + k * 2 * Pi, a2 + k * 2 * Pi);}}}}}printf("%.4f liters\n", ans/10);
}int main() {//freopen("j.txt", "r", stdin);int ncase;scanf("%d", &ncase);for(int _ = 1; _ <= ncase; _++) {printf("Spiral %d: ", _);scanf("%lf", &a);solve();}return 0;
}

UVALive 7345 J - The Hypnotic Spirals相关推荐

  1. Regional 做题记录 (50/50)

    写在前面 博主深感自己太弱了QAQ 于是有了一个刷水的想法,Regional的题目还是有很多考查思维的题目,所以这次是乱做50道思考题,可能会顺带做一些水题,这些题的简要题解会写到这篇博文里面,希望能 ...

  2. Trie UVALive 7192 Chip Factory (15长春J)

    题目传送门 题意:从n个数中选出不同的三个数a b c,使得(a+b)^c 最大 分析:先将所有数字按位插入到字典树上,然后删除两个数字,贪心询问与剩下的数字最大异或值. /************* ...

  3. DP UVALive 6506 Padovan Sequence

    题目传送门 /*题意:两行数字,相邻列一上一下,或者隔一列两行都可以,从左到右选择数字使和最大DP:状态转移方程:dp[i][j] = max (dp[i][j], dp[1-i][j-1] + a[ ...

  4. The UVALIVE 7716 二维区间第k小

    The UVALIVE 7716 二维区间第k小 /** 题意:给一个n * n的矩阵,有q个查询每次查询r,c,s,k表示已(r,c)为右上角 大小为s的正方形中 第k小的元素n <= 250 ...

  5. 逆序数 UVALive 6508 Permutation Graphs

    题目传送门 1 /* 2 题意:给了两行的数字,相同的数字连线,问中间交点的个数 3 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 4 用归并排序或线段树求 ...

  6. UVALive - 8512——线段树维护线性基

    [题目描述] UVALive - 8512XOR [题目分析] 这种区间+线性基的问题我们可以考虑用线段树维护,线性基的合并的话就直接暴力合并 找到所在区间的线性基后再查找最大的数,我看网上的博客要说 ...

  7. POJ 1330 Nearest Common Ancestors / UVALive 2525 Nearest Common Ancestors (最近公共祖先LCA)...

    POJ 1330 Nearest Common Ancestors / UVALive 2525 Nearest Common Ancestors (最近公共祖先LCA) Description A ...

  8. UVALive Problem 7456 Least Crucial Node——Regionals 2015 :: Asia - Taipei

    此文章可以使用目录功能哟↑(点击上方[+])  UVALive Problem 7456 Least Crucial Node Accept: 0    Submit: 0 Time Limit: 3 ...

  9. 训练指南 UVALive - 4043(二分图匹配 + KM算法)

    layout: post title: 训练指南 UVALive - 4043(二分图匹配 + KM算法) author: "luowentaoaa" catalog: true ...

  10. UVALive 4043 Ants(最大权匹配)

    题目链接: UVALive 4043 Ants 题意: 给出平面上n个白点和n个黑点的点坐标,将这n个白点和n个黑点用n条不相交的线段连接,输出每个白点连接的黑点的编号. n<=100. 分析: ...

最新文章

  1. Java跌落神坛,Python继续夺冠....凭啥?
  2. 【图论专题】最小生成树的扩展应用
  3. linux程序移植到vxworks,VxWorks入门(一):VxWorks Vs Linux
  4. 解决apt-get /var/lib/dpkg/lock-frontend 问题
  5. VCL组件之TLabel、TStaticText和TLabeledEdit
  6. jquery ajax POST/GET 请求至 ASP.NET WebAPI
  7. php生日计算年龄,php根据生日计算年龄的方法
  8. 【论文笔记】一种有效攻击BERT等模型的方法
  9. aws iam php,php-AWS4签名密钥-本教程错误吗?
  10. 【控件】mars3d控件的设置
  11. 计算机没有本地网络,网络连接里没有本地连接
  12. 国外苹果id_爆料者称苹果仍在继续研发iPhone屏下Touch ID
  13. ALEXA解释(日IP500,可以使你进10万内)
  14. PHP域名授权查询源码,域名授权系统V1.2完整PHP源码下载_域名授权正版查询系统_源码完全开源...
  15. 团队项目计划、人员安排、方法流程
  16. stc12c5a单片机c语言adc,STC12C5A60S2单片机的ADC采样程序分享
  17. python公式_python公式大全
  18. 高校数字化实验室(实训室)综合管理系统
  19. 打印机打印出来的条码是歪的怎么办
  20. 消防火灾联动报警系统中环网冗余型CAN转光纤的CAN光端机应用

热门文章

  1. 短视频如何打动用户?从人的欲望出发,吸粉引流很简单
  2. 遗传算法详解(GA)(个人觉得很形象,很适合初学者)
  3. 药品质量检测方法:电感耦合等离子体质谱仪
  4. python将多个列表合并_Python中将两个或多个list合成一个list的方法小结
  5. 计算机单位kb和m比较,G、GB、KB、M和MB是怎么回事?
  6. paypal支付开发接口(转)
  7. C# 给Excel添加水印
  8. 微信小程序生成体验版二维码
  9. rsync 同步文件
  10. Linux7安装oracle11g报错 Error in invoking target 'agen