2013-2014 ACM-ICPC, NEERC, Southern Subregional Contest Problem C. Equivalent Cards 计算几何

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;
}

转载于:https://www.cnblogs.com/qscqesze/p/5775227.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/418168.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

String类中不同拼接方式

有变量名参与都不是在常量池中了&#xff0c;类似于new

使用JMeter创建数据库(Mysql)测试

我的环境&#xff1a;MySQL&#xff1a;mysql-essential-5.1.51-win32 jdbc驱动&#xff1a;我已经上传到csdn上一个&#xff1a;http://download.csdn.net/source/3451945 JMeter&#xff1a;jmeter-2.4 任意版本都行。 1.首先我们要有一个可以做测试的数据库&#xff0c;当然…

dtrace

http://dtrace.org/guide/bookinfo.html转载于:https://www.cnblogs.com/WCFGROUP/p/5786990.html

[转载]如何判断js中的数据类型

原文地址&#xff1a;如何判断js中的数据类型作者&#xff1a;最初的你如何判断js中的数据类型&#xff1a;typeof、instanceof、 constructor、 prototype方法比较 如何判断js中的类型呢&#xff0c;先举几个例子&#xff1a; var a "iamstring."; var b 222; var…

String类与其他数据类型得转换

一&#xff1a;与基本数据类型或者包装类 二、String与char型数组得转换 三、String类与字节数组byte[]之间的转换 输出的是字符中得ASCII码。 getBytes使用的默认得编码集 可以自主设置编码集否则为默认编码集 输出&#xff1a;

字符串类中的StringBuffer,StringBuilder

StringBuffer类的常用方法 &#xff0c; String StringBuffer,StringBuilder的效率

JS练习题

输入整数a和b,若a2b2大于100,则输出a2b2百位以上数字,否则输出两数之和<br /><input type"text" id"a" /><br /><input type"text" id"b" /><br /><input type"button" value"点击&q…

JAVA日期和时间API

JDK8以前&#xff1a; public void test2() { // 构造器1&#xff1a;Date date1 new Date();System.out.println(date1); // date1.toString// 构造器2&#xff1a;创建指定毫秒数的Date对象Date date2 new Date(1631722133700L);System.out.println(date2);} JDK8以后: …

Calender日历类

使用方法&#xff1a; Testpublic void test() { // 调用其静态方法得到一个对象Calendar calendar Calendar.getInstance();System.out.println(calendar.getClass()); // 输出的为 GregorianCalendar类// get() 得到所需的数据 比如这一年的第几天int days calendar.…

php-fpm优化

PHP-FPM是一个PHPFastCGI进程管理器&#xff0c;是只用于PHP的。 PHP-FPM其实是PHP源代码的一个补丁&#xff0c;旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中&#xff0c;在编译安装PHP后才可以使用。 现在我们可以在最新的PHP 5.3.2的源码…

JDK8后的日期时间API

Testpublic void test() { // now() 获取当前的时间&#xff0c;日期LocalDate ld LocalDate.now();LocalTime lt LocalTime.now();LocalDateTime ldt LocalDateTime.now();System.out.println(ld);System.out.println(lt);System.out.println(ldt);// of():指定年月日 …

送花(洛谷 2073)

题目背景 小明准备给小红送一束花&#xff0c;以表达他对小红的爱意。他在花店看中了一些花&#xff0c;准备用它们包成花束。 题目描述 这些花都很漂亮&#xff0c;每朵花有一个美丽值W&#xff0c;价格为C。 小明一开始有一个空的花束&#xff0c;他不断地向里面添加花。他有…

nfs服务搭建

service nfs restart nfs服务重启 showmount -e ip地址 查看服务开启状态&#xff1a; chkconfig --list nfs 服务配置&#xff1a; #vim /etc/exports /data/ 192.168.1.145/24(rw,sync) /data/ *(rw,sync,all_squash) 服务重载&#xff0c;不需要restart #/etc/init.d…

爬虫工作量由小到大的思维转变---<第二十五章 Scrapy开始很快,越来越慢(追溯篇)>

爬虫工作量由小到大的思维转变---&#xff1c;第二十二章 Scrapy开始很快,越来越慢(诊断篇)&#xff1e;-CSDN博客 爬虫工作量由小到大的思维转变---&#xff1c;第二十三章 Scrapy开始很快,越来越慢(医病篇)&#xff1e;-CSDN博客 前言: 之前提到过,很多scrapy写出来之后,不…

也许你需要点实用的-Web前端笔试题

之前发的一篇博客里没有附上答案&#xff0c;现在有空整理了下发出来&#xff0c;希望能帮助到正在找工作的你&#xff0c;还是那句话&#xff1a;技术只有自己真正理解了才是自己的东西&#xff0c;共勉。 Web前端笔试题 Htmlcss 1.对WEB标准以及w3c的理解与认识。 标签闭合&a…