JZOJ2135.2017.05.20【usaco2017_Mar Bronze & Silver】C组T3Modern Art

来源:互联网 发布:zxing 二维码java文档 编辑:程序博客网 时间:2024/06/05 17:20

题目描述

   Art critics worldwide have only recently begun to recognize the creative genius behind the great bovine painter, Picowso.   Picowso paints in a very particular way. She starts with an N×Nblank canvas, represented by an N×N grid of zeros, where a zero indicates an empty cell of the canvas. She then draws 9 rectangles on the canvas, one in each of 9 colors (conveniently numbered 1…9). For example, she might start by painting a rectangle in color 2, giving this intermediate canvas:

2220
2220
2220
0000

She might then paint a rectangle in color 7:

2220
2777
2777
0000

And then she might paint a small rectangle in color 3:

2230
2737
2777
0000

Each rectangle has sides parallel to the edges of the canvas, and a rectangle could be as large as the entire canvas or as small as a single cell. Each color from 1…9 is used exactly once, although later colors might completely cover up some of the earlier colors.

Given the final state of the canvas, please count how many of the colors still visible on the canvas could have possibly been the first to be painted.

输入

The first line of input contains N, the size of the canvas (1≤N≤10). The next N lines describe the final picture of the canvas, each containing N numbers that are in the range 0…9. The input is guaranteed to have been drawn as described above, by painting successive rectangles in different colors.

输出

Please output a count of the number of colors that could have been drawn first, from among all colors visible in the final canvas.

样例输入

4
2230
2737
2777
0000

样例输出

1

数据范围限制

提示

In this example, only color 2 could have been the first to be painted. Color 3 clearly had to have been painted after color 7, and color 7 clearly had to have been painted after color 2.

译文:
题目描述
艺术评论家世界最近才开始认识到背后的巨大牛画家的创作天才,Picowso。
picowso涂料在一个非常特别的方式。她开始与N×nblank帆布,由N×N网格零表示,其中一零表示的画布上的一个空的细胞。然后她在画布上画了9个矩形,每9个颜色中有一个(方便编号为1…)。例如,她可能开始画一个长方形的颜色2,给这个中间画布:
二千二百二十
二千二百二十
二千二百二十
0000
然后,她可能会画一个长方形的颜色7:
二千二百二十
二千七百七十七
二千七百七十七
0000
然后她可以画一个小矩形的颜色3:
二千二百三十
二千七百三十七
二千七百七十七
0000
每个矩形都有平行于画布边缘的边,矩形可以和整个画布一样大,也可以和单个单元格一样小。每个颜色从1…9是完全使用一次,虽然后来的颜色可能完全掩盖了一些早期的颜色。
鉴于画布的最后状态,请数一数画布上仍然可见多少颜色可能是第一个被绘制的颜色。
输入
输入的第一行包含N,画布的大小(1≤N≤10)。接下来的N行描述了画布的最后一幅图,每个画面包含n个数字,范围在0…9。输入保证已绘制如上所述,通过绘制连续的矩形在不同的颜色。
输出
请输出一个数字的颜色,可能已经画第一,从所有颜色可见在最后的画布。
样例输入

二千二百三十
二千七百三十七
二千七百七十七
0000
样例输出

数据范围限制
提示
在这个例子中,只有颜色2可能是第一个被描绘。颜色3清楚地已被画后,颜色7,和颜色7清楚地已被画后,颜色2。

思路:
之前没有做
实际很简单,基本上所有人思路是一样的:
找到一个颜色,向他的上下左右方向扩展,直到去到上下左右的最大值
然后若当前这种颜色的矩形里含有其他颜色,那这个矩形里面的颜色一定是后来画的
为什么?
因为这里面的颜色覆盖了矩形的颜色,所以它一定是后来画的
每个不可能成立的颜色用布尔数组搞一搞,最后输出

代码:

var        up,down,left,right:array['0'..'9']of longint;        bz:array['0'..'9']of boolean;        a:array[0..10,0..10]of char;        n,i,j,ans:longint;        ch:char;function max(x,y:longint):longint;begin        if x>y then exit(x);        exit(y);end;function min(x,y:longint):longint;begin        if x<y then exit(x);        exit(y);end;begin        assign(input,'art.in');reset(input);        assign(output,'art.out');rewrite(output);        fillchar(up,sizeof(up),127);        fillchar(left,sizeof(left),127);        readln(n);        for i:=1 to n do        begin                for j:=1 to n do                begin                        read(a[i,j]);                        bz[a[i,j]]:=true;                        up[a[i,j]]:=min(up[a[i,j]],i);                        down[a[i,j]]:=max(down[a[i,j]],i);                        left[a[i,j]]:=min(left[a[i,j]],j);                        right[a[i,j]]:=max(right[a[i,j]],j);                end;                readln;        end;        for ch:='1' to '9' do                for i:=up[ch]to down[ch]do                        for j:=left[ch]to right[ch]do                                if a[i,j]<>ch then                                        bz[a[i,j]]:=false;        for ch:='1' to '9'do                if bz[ch] then inc(ans);        writeln(ans);end.
阅读全文
0 0
原创粉丝点击