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

博客探讨了一位名为Picowso的牛画家独特的绘画方式,通过模拟9种颜色的矩形覆盖,分析如何确定画布上哪个颜色可能是最先绘制的。给出输入输出样例和解题思路,涉及寻找颜色区域并判断覆盖顺序。

题目描述

   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.
linux oracle服务器内存占用高,通过top发现都是oracle的进程,如何分析及处理。 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 94000 oracle 20 0 77.4g 9.6g 9.6g S 0.0 3.8 1:44.82 oracle_94000_to 78904 oracle 20 0 77.4g 9.4g 9.4g S 0.0 3.7 0:33.05 oracle_78904_to 105090 oracle 20 0 77.4g 8.6g 8.6g S 2.3 3.4 0:15.19 oracle_105090_t 105104 oracle 20 0 77.4g 7.9g 7.9g S 0.0 3.2 0:33.34 oracle_105104_t 105180 oracle 20 0 77.4g 7.6g 7.6g S 0.0 3.0 0:15.68 oracle_105180_t 145666 oracle 20 0 77.4g 7.4g 7.4g S 0.0 2.9 1:04.69 oracle_145666_t 97261 oracle 20 0 77.4g 6.9g 6.9g S 0.0 2.8 0:27.21 oracle_97261_to 53556 oracle 20 0 77.4g 6.9g 6.9g S 0.0 2.7 0:31.96 oracle_53556_to 53377 oracle 20 0 77.4g 6.8g 6.8g S 73.5 2.7 0:22.55 oracle_53377_to 152865 oracle 20 0 77.4g 6.8g 6.8g S 0.0 2.7 1:00.67 oracle_152865_t 1180 oracle 20 0 77.4g 6.6g 6.6g S 1.3 2.6 0:42.97 oracle_1180_top 1222 oracle 20 0 77.4g 6.6g 6.6g S 0.0 2.6 0:56.87 oracle_1222_top 53372 oracle 20 0 77.4g 6.3g 6.3g S 0.0 2.5 0:40.49 oracle_53372_to 105085 oracle 20 0 77.4g 6.3g 6.3g S 0.0 2.5 0:09.58 oracle_105085_t 105187 oracle 20 0 77.4g 6.0g 6.0g S 0.0 2.4 0:30.22 oracle_105187_t 105083 oracle 20 0 77.4g 5.7g 5.7g S 0.0 2.3 0:24.42 oracle_105083_t 53384 oracle 20 0 77.4g 5.7g 5.7g S 64.9 2.3 0:24.07 oracle_53384_to 105111 oracle 20 0 77.4g 5.6g 5.6g S 0.0 2.2 0:24.56 oracle_105111_t 105075 oracle 20 0 77.4g 5.6g 5.6g S 0.3 2.2 0:25.86 oracle_105075_t 53323 oracle 20 0 77.4g 5.3g 5.3g S 0.0 2.1 0:16.96 oracle_53323_to 105070 oracle 20 0 77.4g 5.2g 5.2g S 0.0 2.1 0:18.44 oracle_105070_t 105079 oracle 20 0 77.4g 4.9g 4.9g S 0.0 1.9 0:18.04 oracle_105079_t 105098 oracle 20 0 77.4g 4.8g 4.8g S 0.0 1.9 0:06.61 oracle_105098_t 105077 oracle 20 0 77.4g 4.8g 4.8g S 2.3 1.9 0:14.32 oracle_105077_t 105106 oracle 20 0 77.4g 4.7g 4.7g S 0.0 1.9 0:08.15 oracle_105106_t 105081 oracle 20 0 77.4g 4.6g 4.6g S 0.0 1.8 0:12.40 oracle_105081_t 105068 oracle 20 0 77.4g 4.3g 4.3g S 0.0 1.7 0:14.12 oracle_105068_t 3292 oracle 20 0 77.4g 4.2g 4.2g S 0.3 1.7 7:06.41 ora_dbw1_topprd 3298 oracle 20 0 77.4g 4.2g 4.2g S 0.0 1.7 6:58.30 ora_dbw2_topprd 3288 oracle 20 0 77.4g 4.0g 4.0g S 0.0 1.6 7:04.16 ora_dbw0_topprd 137170 oracle 20 0 77.4g 3.9g 3.9g S 0.0 1.5 0:04.14 oracle_137170_t 3254 oracle 20 0 77.4g 2.8g 2.8g S 0.0 1.1 0:12.17 ora_mman_topprd 3268 oracle 20 0 77.4g 2.1g 2.1g S 0.0 0.8 3:05.20 ora_dbrm_topprd 53325 oracle 20 0 77.4g 1.1g 1.1g S 0.0 0.4 0:23.76 oracle_53325_to 63393 oracle 20 0 77.4g 1.1g 1.1g S 0.0 0.4 0:15.74 ora_w00j_topprd 153706 oracle 20 0 77.4g 1.1g 1.1g S 0.0 0.4 0:14.09 ora_w006_topprd 165413 oracle 20 0 77.4g 1.1g 1.0g S 0.0 0.4 0:12.37 ora_w00a_topprd 78207 oracle 20 0 77.4g 1.1g 1.0g S 0.0 0.4 0:11.43 ora_w007_topprd 157015 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:12.00 ora_w00c_topprd 73660 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:13.04 ora_w00f_topprd 70189 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:11.33 ora_w005_topprd 190361 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:11.17 ora_w001_topprd 194992 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:11.84 ora_w00l_topprd 3240 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:14.04 ora_w00h_topprd 69791 oracle 20 0 77.4g 1.0g 1.0g S 0.0 0.4 0:14.72 ora_w00e_topprd 193243 oracle 20 0 77.4g 992.3m 989.1m S 0.0 0.4 0:10.89 ora_w000_topprd 104520 oracle 20 0 77.4g 990656 986464 S 0.0 0.4 0:09.29 ora_w00b_topprd 111719 oracle 20 0 77.4g 981984 977172 S 0.0 0.4 0:02.51 oracle_111719_t 107025 oracle 20 0 77.4g 965608 961772 S 0.3 0.4 0:09.03 ora_w00i_topprd
最新发布
08-15
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值