Problem C. Equivalent Cards

题目连接:

http://www.codeforces.com/gym/100253

Description

Jane is playing a game with her friends. They have a deck of round cards of radius 100. Each card has a

set of disjoint rectangles strictly within the bounding circle. The rectangles' vertices and the card center

have integer coordinates. However, the rectangles' edges are not necessarily parallel to the axes. The value

of a card depends on the rectangles in it and equals the sum of areas of all its rectangles. The cards are

equivalent if they have same values.

The rules are simple. Each player is given a card in the beginning. Then they turn the cards face-up. If

any player can spot another player's card equivalent to their own card, the player who rst noticed the

equivalency gives their cards to another player and draws a new card from the deck face-up. The game

ends when there are no equivalent cards among players, or when a player needs to draw a card, but the

deck is empty. The player with the least number of cards wins.

Of course, Jane never cheats. She also believes that her friends don't cheat as well. But the game is so

dynamic, that there is no time to verify if some cards are equivalent, i.e. have the same total area of

rectangles. So, if somebody makes a mistake and claims that two cards are equivalent while they are not,

other players may leave it unnoticed and keep playing.

To avoid this, Jane decided to use her web-camera and write a program to nd equivalent cards. She noticed

that cards on the pictures from the camera taken under some angle look like ellipses and rectangles look

like parallelograms, but she is not good at geometry. Also the images are scaled, shifted and rotated, so

the problem seems to be too hard to Jane. She asked you to write an algorithm to nd equivalent cards.

Fortunately, you know a good image processing library which does the hardest work of nding gures for

you. Your task is, given the library output, nd all equivalence classes and for each card tell which class

it belongs to. An equivalence class is a set of cards having the same sum of areas of rectangles.

Input

The rst line of the input contains n (1 ≤ n ≤ 100), where n is the number of pictures. Each picture

contains a single card in it.

Then n descriptions of pictures follow. The description of a picture consists of several lines. The rst

two lines of the description specify an ellipse a card boundary on the picture. The rst line contains

coordinates of two most distant opposite points on the ellipse (any pair of opposite points in case of a

tie). The second line contains the coordinates of two closest opposite points on the ellipse (any pair of

opposite points in case of a tie), the distance between them is at least 1. These four points completely

determine the ellipse. The following line contains ri (1 ≤ ri ≤ 4) the number of rectangles on the card.

The following ri blocks contain the coordinates of four points, a pair of coordinates per line. Each point

is a corner of a corresponding parallelogram on the picture in the clockwise or counter-clockwise order.

All coordinates are oating point numbers between -1000 and 1000, inclusively. They are given with an

accuracy of exactly 8 digits after the decimal point

Output

Print the only line containing the sequence f1, f2, . . . , fn describing the equivalence classes. It should be

true that fi = fj if and only if the i-th and the j-th cards are equivalent. You may use any integer values

between 1 and 100 inclusive.

Sample Input

3

-10.00000000 0.00000000 10.00000000 0.00000000

0.00000000 -10.00000000 0.00000000 10.00000000

2

5.00000000 5.00000000

5.00000000 6.00000000

6.00000000 6.00000000

6.00000000 5.00000000

3.00000000 2.00000000

3.00000000 1.00000000

4.00000000 1.00000000

4.00000000 2.00000000

-8.00000000 -6.00000000 8.00000000 6.00000000

6.00000000 8.00000000 -6.00000000 -8.00000000

1

1.00000000 0.00000000

0.00000000 1.00000000

-1.00000000 0.00000000

0.00000000 -1.00000000

-10.00000000 0.00000000 10.00000000 0.00000000

0.00000000 -5.00000000 0.00000000 5.00000000

1

1.00000000 1.00000000

0.00000000 1.00000000

0.00000000 -1.00000000

1.00000000 -1.00000000

Sample Output

1 1 2

Hint

题意

说平面上有一个圆,圆内有很多正方形,现在这个圆被拉伸成为了一个椭圆,里面的正方形就被拉成了平行四边形。

现在问你按照面积和分类,这些圆能够分成几类

题解:

椭圆面积为piab,平行四边形面积为ab,所以两个图形是等比例放缩的,那就直接按照比例算就好了……

代码

#include<bits/stdc++.h>
using namespace std;
const double INF = 1E200 ;
const double EP = 1E-10 ;
const int MAXV = 300 ;
const double PI = 3.14159265 ;
/* 基本几何结构 */
struct POINT
{
double x;
double y;
POINT(double a=0, double b=0) { x=a; y=b;} //constructor
};
struct LINESEG
{
POINT s;
POINT e;
LINESEG(POINT a, POINT b) { s=a; e=b;}
LINESEG() { }
};
struct LINE // 直线的解析方程 a*x+b*y+c=0 为统一表示,约定 a >= 0
{
double a;
double b;
double c;
LINE(double d1=1, double d2=-1, double d3=0) {a=d1; b=d2; c=d3;}
};
LINE makeline(POINT p1,POINT p2)
{
LINE tl;
int sign = 1;
tl.a=p2.y-p1.y;
if(tl.a<0)
{
sign = -1;
tl.a=sign*tl.a;
}
tl.b=sign*(p1.x-p2.x);
tl.c=sign*(p1.y*p2.x-p1.x*p2.y);
return tl;
}
bool lineintersect(LINE l1,LINE l2,POINT &p) // 是 L1,L2
{
double d=l1.a*l2.b-l2.a*l1.b;
if(abs(d)<EP) // 不相交
return false;
p.x = (l2.c*l1.b-l1.c*l2.b)/d;
p.y = (l2.a*l1.c-l1.a*l2.c)/d;
return true;
}
/*
r=dotmultiply(p1,p2,op),得到矢量(p1-op)和(p2-op)的点积,如果两个矢量都非零矢量
r<0:两矢量夹角为钝角;
r=0:两矢量夹角为直角;
r>0:两矢量夹角为锐角
*******************************************************************************/
double dist(POINT p1,POINT p2) // 返回两点之间欧氏距离
{
return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
double multiply(POINT sp,POINT ep,POINT op)
{
return((sp.x-op.x)*(ep.y-op.y)-(ep.x-op.x)*(sp.y-op.y));
}
double dotmultiply(POINT p1,POINT p2,POINT p0)
{
return ((p1.x-p0.x)*(p2.x-p0.x)+(p1.y-p0.y)*(p2.y-p0.y));
}
double relation(POINT p,LINESEG l)
{
LINESEG tl;
tl.s=l.s;
tl.e=p;
return dotmultiply(tl.e,l.e,l.s)/(dist(l.s,l.e)*dist(l.s,l.e));
}
// 求点C到线段AB所在直线的垂足 P
POINT perpendicular(POINT p,LINESEG l)
{
LINE l1=makeline(l.s,l.e);
LINE l2=l1;
l2.c=-(l1.a*p.x+l2.b*p.y);
}
double dis(POINT A,POINT B)
{
return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}
double solve()
{
POINT p1,p2,p3,p4,P[4],mid;
double ans=0;
scanf("%lf%lf%lf%lf",&p1.x,&p1.y,&p2.x,&p2.y);
scanf("%lf%lf%lf%lf",&p3.x,&p3.y,&p4.x,&p4.y);
mid.x=(p1.x+p2.x)/2.0,mid.y=(p1.y+p2.y)/2.0;
double tmp=dist(p1,p2)*dist(p3,p4);
int q;
scanf("%d",&q);
for(int i=0;i<q;i++)
{
for(int i=0;i<4;i++)
scanf("%lf%lf",&P[i].x,&P[i].y);
ans+=abs(multiply(P[0],P[2],P[1]));
}
return ans/tmp;
}
double area[5000];
int Ans[5005];
int main()
{
int t;
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
Ans[i]=i;
area[i]=solve(); } for(int i=1;i<=t;i++)
{
for(int j=1;j<i;j++)
{
if(abs(area[i]-area[j])<1e-6)
{
Ans[i]=Ans[j];
break;
}
}
}
for(int i=1;i<=t;i++)
{
if(i==1)printf("%d",Ans[i]);
else printf(" %d",Ans[i]);
}
printf("\n");
return 0;
}

2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem C. Equivalent Cards 计算几何的更多相关文章

  1. 2018-2019 ICPC, NEERC, Southern Subregional Contest

    目录 2018-2019 ICPC, NEERC, Southern Subregional Contest (Codeforces 1070) A.Find a Number(BFS) C.Clou ...

  2. Codeforces 2018-2019 ICPC, NEERC, Southern Subregional Contest

    2018-2019 ICPC, NEERC, Southern Subregional Contest 闲谈: 被操哥和男神带飞的一场ACM,第一把做了这么多题,荣幸成为7题队,虽然比赛的时候频频出锅 ...

  3. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror) Solution

    从这里开始 题目列表 瞎扯 Problem A Find a Number Problem B Berkomnadzor Problem C Cloud Computing Problem D Gar ...

  4. Codeforces1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)总结

    第一次打ACM比赛,和yyf两个人一起搞事情 感觉被两个学长队暴打的好惨啊 然后我一直做傻子题,yyf一直在切神仙题 然后放一波题解(部分) A. Find a Number LINK 题目大意 给你 ...

  5. codeforce1070 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) 题解

    秉承ACM团队合作的思想懒,这篇blog只有部分题解,剩余的请前往星感大神Star_Feel的blog食用(表示男神汉克斯更懒不屑于写我们分别代写了下...) C. Cloud Computing 扫 ...

  6. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)

    A. Find a Number 找到一个树,可以被d整除,且数字和为s 记忆化搜索 static class S{ int mod,s; String str; public S(int mod, ...

  7. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...

  8. 2018-2019 ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred) Solution

    A. Find a Number Solved By 2017212212083 题意:$找一个最小的n使得n % d == 0 并且 n 的每一位数字加起来之和为s$ 思路: 定义一个二元组$< ...

  9. 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing

    [链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...

随机推荐

  1. python 玩具代码

    脚本语言的第一行,目的就是指出,你想要你的这个文件中的代码用什么可执行程序去运行它,就这么简单 #!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的python ...

  2. Spring Cloud (十五)Stream 入门、主要概念与自定义消息发送与接收

    前言 不写随笔的日子仿佛就是什么都没有产出一般--上节说到要学Spring Cloud Bus,这里发现按照官方文档的顺序反而会更好些,因为不必去后边的章节去为当前章节去打基础,所以我们先学习Spri ...

  3. JMS学习(五)--ActiveMQ中的消息的持久化和非持久化 以及 持久订阅者 和 非持久订阅者之间的区别与联系

    一,消息的持久化和非持久化 ①DeliveryMode 这是传输模式.ActiveMQ支持两种传输模式:持久传输和非持久传输(persistent and non-persistent deliver ...

  4. 如何教会老婆写 Python ?

    什么是code? code就就是一种语言,一种计算机能读懂的语言.计算机是一个傻逼,他理解不了默认两可的任何东西. 比如,你让你老公去买个西瓜,你老公会自己决定去哪里买,买几个,找个搞活动打折的买,总 ...

  5. JDK1.8源码Collections

    正文: 一.概述: 此类完全由在 collection 上进行操作或返回 collection 的静态方法组成.它包含在 collection 上操作的多态算法,即“包装器”,包装器返回由指定 col ...

  6. Nagios介绍

    Nagios介绍 Nagios是一款功能强大.优秀的开源监控系统,它能够让你发现和解决IT架构中存在的问题,避免这些问题影响到关键业务流程. Nagios最早于1999年发布,它在开源社区的影响力是相 ...

  7. Replication容量和错误日志

    gtid排错 set sql_log_bin=off;  #人为关闭二进制日志

  8. 使用SpringCloud搭建高可用服务注册中心

    我们需要的,不仅仅是一个服务注册中心而已,而是一个高可用服务注册中心. 上篇博客中我们介绍了如何使用Spring Cloud搭建一个服务注册中心,但是搭建好的服务注册中心是一个单节点的服务注册中心,这 ...

  9. 在Scrapy项目【内外】使用scrapy shell命令抓取 某网站首页的初步情况

    Windows 10家庭中文版,Python 3.6.3,Scrapy 1.5.0, 时隔一月,再次玩Scrapy项目,希望这次可以玩的更进一步. 本文展示使用在 Scrapy项目内.项目外scrap ...

  10. C++ Primer读书笔记(3)

    vector: 本科时学C++的时候没学过vector,正好补一下. 第一个要注意的地方是要正确区分列表初始值还是元素数量. 第二点是不能使用范围for向vector对象添加元素,范围for语句体内不 ...