zoukankan      html  css  js  c++  java
  • CodingTrip

    位图像素的颜色

    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other)
    Total Submission(s) : 1   Accepted Submission(s) : 1

    Font: Times New Roman | Verdana | Georgia

    Font Size:  

    Problem Description

    有一个在位图上画出矩形程序,一开始位图都被初始化为白色(RGB颜色表示为R=G=B=255)。该程序能够按照顺序绘出N个矩形。新绘制的矩形能够覆盖位图上原有的颜色。程序执行完毕后,需要查询M个点的颜色,输出这些点的RGB值。

    每组数据都是在初始化后开始绘制。

    Input

    第一行包含参数N和M,分别表示矩形个数和需要查询的像素个数(1 ≤N, M≤ 1000 );
    剩下N行每行包含7个参数x1, y1, x2, y2, r, g, b,表示绘制一个(x1,y1),(x2,y2)为顶点的矩形,填充颜色为RGB(r, g, b),其中x1≤x2, y1≤y2数据在整型范围;0≤ r,g,b ≤ 255;
    最后M行分别包含参数X和Y,表示需要查询的像素位置。
    如果某行N=M=0就表示输入结束。

    Output

    对于每个用例,按行输出查询的像素的RGB值,每行包含3个整数,分别表示RGB值。

    Sample Input

    1 2
    0 0 2 3 127 196 200 
    1 2
    3 0
    2 3
    8 16 32 64 0 255 128 
    8 48 32 64 255 0 0 
    12 47
    13 48
    14 64
    0 0

    Sample Output

    127 196 200
    255 255 255
    0 255 128
    255 0 0
    255 0 0


    我们可以把n个矩形先存起来,因为后面的涂色会把前面的覆盖掉,所以对于n次询问,我只要找到最后一个包含这个点的矩形,并把它的像素输出就可以了。因为n和m的范围都是不超过1000的,所以n*m不会超时。
     1 /*
     2 ID: asif
     3 LANG: C++
     4 TASK: test
     5 */
     6 //# pragma comment(linker, "/STACK:102400000,102400000")
     7 # include<iostream>
     8 # include<cstdio>
     9 # include<cstdlib>
    10 # include<cstring>
    11 # include<algorithm>
    12 # include<cctype>
    13 # include<cmath>
    14 # include<string>
    15 # include<set>
    16 # include<map>
    17 # include<stack>
    18 # include<queue>
    19 # include<vector>
    20 # include<numeric>
    21 using namespace std;
    22 const int maxn=1011;
    23 const double inf=0.000001;
    24 const int INF=~0U>>1;
    25 const int mod=1000000007;
    26 # define PI (acos(0)*2.0)
    27 # define lson l,m,rt<<1
    28 # define rson m+1,r,rt<<1 | 1
    29 # define PS printf("
    ")
    30 # define S(n) scanf("%d",&n)
    31 # define P(n) printf("%d
    ",n)
    32 # define Ps(n) printf(" %d",(n))
    33 # define SB(n) scanf("%lld",&n)
    34 # define PB(n) printf("%lld
    ",n)
    35 # define PBs(n) printf(" %lld",n)
    36 # define SD(n) scanf("%lf",&n)
    37 # define PD(n) printf("%.3lf
    ",n)
    38 # define Sstr(s) scanf("%s",s)
    39 # define Pstr(s) printf("%s
    ",s)
    40 # define S0(a) memset(a,0,sizeof(a))
    41 # define S1(a) memset(a,-1,sizeof(a))
    42 typedef long long ll;
    43 int n,m;
    44 struct node
    45 {
    46     int x1;
    47     int y1;
    48     int x2;
    49     int y2;
    50     int r;
    51     int g;
    52     int b;
    53 };
    54 node point[maxn];
    55 int equal(double x,double y)
    56 {
    57     if(x-y>=-inf&&x-y<=inf)
    58         return 0;
    59     else if(x-y>inf)
    60         return 1;
    61     return -1;
    62 }
    63 int main()
    64 {
    65     //freopen("input.in", "r", stdin);
    66     //freopen("output.out", "w", stdout);
    67     while(cin>>n>>m,n||m)
    68     {
    69         for(int i=0;i<n;i++)
    70             scanf("%d%d%d%d%d%d%d",&point[i].x1,&point[i].y1,&point[i].x2,&point[i].y2,&point[i].r,&point[i].g,&point[i].b);
    71         for(int i=0;i<m;i++)
    72         {
    73             int x,y;
    74             S(x),S(y);
    75             int r=255,g=255,b=255;
    76             for(int j=0;j<n;j++)
    77             {
    78                 if(x>=point[j].x1&&x<=point[j].x2&&y>=point[j].y1&&y<=point[j].y2)
    79                 {
    80                     r=point[j].r;
    81                     g=point[j].g;
    82                     b=point[j].b;
    83                 }
    84             }
    85             printf("%d %d %d
    ",r,g,b);
    86         }
    87     }
    88     return 0;
    89 }
    View Code
  • 相关阅读:
    350. Intersection of Two Arrays II
    94. Binary Tree Inorder Traversal
    623. Add One Row to Tree
    JS判断是否为数字,中文,小写、大写字母
    ASP.NET 操作Cookie详解 增加,修改,删除
    ASP.NET MVC 入门1、简介
    通过LINQ TO SQL类显示数据库表的数据
    OutputCache缓存优化asp.net代码 提高网页性能
    数据库读取二进制图片显示到PictureBox中
    WinForm窗体间如何传值的几种方法
  • 原文地址:https://www.cnblogs.com/asif/p/3659999.html
Copyright © 2011-2022 走看看