ZOJ 3364题解
来源:互联网 发布:印度超级联赛直播数据 编辑:程序博客网 时间:2024/06/06 09:27
题目连接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26405#problem/C
题意:
找出多边形中又都少个白格子和多少个黑格子。(多边形的所有边都是平行一坐标轴的)。
本题的思路:
先把坐标原点移到很远的地方去,那就是给输入的所有坐标都加上10^9;(这样就可以保证所有的坐标都为正),
然后本题的坐标是逆时针给出的,所以令第一个给出的坐标为(x1,y1),令第二个坐标为(x2,y2);若x1==x2,那么
多边形的面积sum+=(x1-x2)*y1;如果x1!=x2,那么把(x2,y2)的值付给(x1,y1),然后输入(x2,y2),重复上面的操作。
便可以得到总面积了。然后再求黑格子的个数。方法同求总面积类似,再求一下(x,y)到原点的面积,如果面积为奇数,那么黑格子和白格子的个数相同,否则,
看看(x+y)是否为偶数,则黑格子要多一个,否则则白格子多一个。
代码:
#include<stdio.h>#define inf 1000000010long long T,i,x0,y0,x1,y1,sum,b,temp,x,y;int main(){ while(~scanf("%lld",&T)){ sum=0;b=0; scanf("%lld %lld",&x0,&y0); x0=x0+inf; y0=y0+inf; x=x0; y=y0; for(i=1;i<T;i++){ scanf("%lld %lld",&x1,&y1); x1=x1+inf; y1=y1+inf; if(y0==y1){ sum=sum+(x0-x1)*y0; //printf("sum=%lld\n",sum); temp=x0*y0; if(temp%2==0){ b+=temp/2; }else{ if((x0+y0)%2==0){ b+=temp/2+1; }else{ b+=temp/2; } } temp=x1*y1; if(temp%2==0){ b-=temp/2; }else{ if((x1+y1)%2==0){ b-=(temp/2+1); }else{ b-=temp/2; } } x0=x1; y0=y1; }else{ x0=x1; y0=y1; } //printf("b=%lld\n",b); } if(y==y1){ //printf("%lld\n",(x1-x)*y1); sum+=(x1-x)*y1; //printf("sum=%lld\n",sum); temp=x1*y1; if(temp%2==0){ b+=temp/2; }else{ if((x1+y1)%2==0){ b+=temp/2+1; }else{ b+=temp/2; } } temp=x*y; if(temp%2==0){ b-=temp/2; }else{ if((x+y)%2==0){ b-=(temp/2+1); }else{ b-=temp/2; } } } //printf("b=%lld\n",b); printf("%lld ",b); printf("%lld\n",sum-b); }return 0;}
- ZOJ 3364题解
- ZOJ题解
- zoj 1387 译题+题解
- zoj 1438 - Asteroids! 题解
- zoj--1089--Lotto题解
- ZOJ 3369题解
- ZOJ 3551 Bloodsucker 题解
- ZOJ 2923 题解
- ZOJ 3659 题解
- ZOJ 1909Square 题解
- zoj 2050 -Flip Game题解
- zoj 3725 Painting Storages 题解
- ZOJ Monthly, August 2012 题解
- ZOJ 3057 Beans Game题解
- ZOJ 3958 Cooking Competition 题解
- ZOJ-1002 Fire Net 火力网 题解
- ZOJ月赛部分题解题报告
- POJ 1974和ZOJ 2499题解
- 解读一淘网(etao)首页响应式兼容ie6~ie8实现方法
- Direct3D 11 简介
- php错误级别
- HDU 4618
- MySQL数据库问题收集
- ZOJ 3364题解
- Direct3D 11的流水线
- 字符数据与整形数据的转换
- XCode常用快捷键
- Direct3D 11的资源
- 非类型模板形参取数组的维数
- QQ登陆页面用java实现
- lightoj-1427:Substring Frequency
- Codeigniter框架使用问题(持续更新……)