Flipping colors

问题五: Flipping colors

Input:colors.in output:colors.out

       一个各边与x-y轴平行的矩形其左下角在(00)要被涂色。矩形可被看作有无穷解析度的平面显示器,开始整个矩形是黑的。给定两个数h,v0 < h, v < 1,且:

画一条竖线,使矩形水平边从左边开始被分割为h:1-h

画一条水平线,把矩形从下向上分割为v:1-v

  • 这两条线把矩形分割四个小矩形
  • 左上方和右下方的小矩形保持不变
  • 其他两个矩形被涂色(从黑到白或从白到黑),再对每个小矩形重复上述的分割步骤
  • 这个过程继续一直到无穷(原理上是这样)

       给定原矩形内的一个点,它不会出现在涂色过程中产生的所有小矩形的边界上,试确定这点的颜色。

    有多个测试用例,每个测试用例的第一行有4个数,分别是矩形的长H,矩形的高V,及两个数h,v。第二行是整数n,是要考虑的点的个数。随后的n行每行是两个数x,y是一个点的坐标。

    按样例组织你的输出。对输入的每个点,输出该点的颜色。


Sample input

81 32 0.333333333333 0.5   
6
16 30
16 25
16 12.0001
16 11.9999
16 7.987654321
16 7.0123456789
10 10 0.123456789 0.987654321
2
0.432 0.9876
9.432 0.9876
0 0 0 0

  
  
   
    
  
  

Output for sample input

Case 1:
black
black
white
black
white
white
Case 2:
white
black

 

import  java.io. * ;
import  java.util. * ;
class  point
{
    
double x,y;    
    
public point(double x,double y)
    
{
        
this.x=x;
        
this.y=y;        
    }

}

class  Test5 
{
    
//static int cout;    
    public static void main(String[] args) throws Exception
    
{
        BufferedReader bf
=new BufferedReader(new FileReader("colors.in"));
        String str;
        String tmp[];
        
int rank=0;
        
while(!(str=bf.readLine()).equals("0 0 0 0"))
        
{
            
int cout=0;            
            rank
++;
            tmp
=str.split(" ");
            
double H=Double.parseDouble(tmp[0]);
            
double V=Double.parseDouble(tmp[1]);
            
double h=Double.parseDouble(tmp[2]);
            
double v=Double.parseDouble(tmp[3]);
            
int m=Integer.parseInt(bf.readLine());
            point p[]
=new point[m];
            
for(int i=0;i<m;i++)
            
{
                tmp
=bf.readLine().split(" ");
                p[i]
=new point(Double.parseDouble(tmp[0]),Double.parseDouble(tmp[1]));
            }

            System.out.println(
"Case "+rank+":");
            
for(int i=0;i<m;i++)
            go(p[i],
0,0,H,V,h,v,cout);                    
        }
//end while
    }
//end main
    public static void go(point p,double x1,double y1,double x2,double y2,double h,double v,int cout)throws Exception
    
{
        
double x=(x2-x1)*h+x1;
        
double y=(y2-y1)*v+y1;
        
if(p.x<x&&p.y>y){if(cout%2==0)System.out.println("black");else System.out.println("white");return;}
        
if(p.x>x&&p.y<y){if(cout%2==0)System.out.println("black");else System.out.println("white");return;}
        
if(p.x<x&&p.y<y)
        go(p,x1,y1,x,y,h,v,cout
+1);
        
else
        go(p,x,y,x2,y2,h,v,cout
+1);        
    }
//end go
}

 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值