JZOJ2137.2017.05.20【usaco2017_Mar Bronze & Silver】C组T5Bovine Genomics

农民约翰研究牛的基因组以解释其斑点特征。通过对每头牛的基因组进行测序,他发现可能有3个特定位置的组合可以准确预测斑点。给定所有牛的基因组,任务是找出能完美预测斑点的三个不同位置的组合数量。

题目描述

Farmer John owns N cows with spots and N cows without spots. Having just completed a course in bovine genetics, he is convinced that the spots on his cows are caused by mutations in the bovine genome.

At great expense, Farmer John sequences the genomes of his cows. Each genome is a string of length Mbuilt from the four characters A, C, G, and T. When he lines up the genomes of his cows, he gets a table like the following, shown here for N=3:

Positions: 1 2 3 4 5 6 7 … M

Spotty Cow 1: A A T C C C A … T
Spotty Cow 2: G A T T G C A … A
Spotty Cow 3: G G T C G C A … A

Plain Cow 1: A C T C C C A … G
Plain Cow 2: A G T T G C A … T
Plain Cow 3: A G T T C C A … T

Looking carefully at this table, he surmises that positions 2 and 4 are sufficient to explain spottiness. That is, by looking at the characters in just these two positions, Farmer John can predict which of his cows are spotty and which are not (for example, if he sees G and C, the cow must be spotty).

Farmer John is convinced that spottiness can be explained not by just one or two positions in the genome, but by looking at a set of three distinct positions. Please help him count the number of sets of three distinct positions that can each explain spottiness.

输入

The first line of input contains N (1≤N≤500) and M (3≤M≤50). The next N lines each contain a string of M characters; these describe the genomes of the spotty cows. The final N lines describe the genomes of the plain cows.

输出

Please count the number of sets of three distinct positions that can explain spottiness. A set of three positions explains spottiness if the spottiness trait can be predicted with perfect accuracy among Farmer John’s population of cows by looking at just those three locations in the genome.

样例输入

3 8
AATCCCAT
GATTGCAA
GGTCGCAA
ACTCCCAG
ACTCGCAT
ACTTCCAT

样例输出

22

数据范围限制

译文:
题目描述
农民约翰拥有N点奶牛和奶牛没有斑点。刚刚完成了牛遗传学的课程,他确信牛的斑点是由牛基因组的突变引起的。
在巨大的开支,农民约翰测序他的牛的基因组。每个基因组是一个字符串的长度从四mbuilt字符A,C,G,T的时候,他行了他的牛的基因组,他得到一个表像的下面,此处显示的为N = 3:
岗位:2人3人4人6人5人7人…M
斑点母牛1:一一吨C…T
斑点母牛2:G一个…一
斑点母牛3:G * T * C…一
普通奶牛1:一个C…G
普通奶牛2:一只…T
普通奶牛3:一只…T
仔细地看这张桌子,他推测,位置2和4都足以说明有斑点。也就是说,通过看在这两个位置的字符,农民约翰可以预测他的牛是斑点,哪些是不(例如,如果他看到G和C,牛必须斑点)。
农民约翰相信有斑点可以解释不只是一个或两个位置在基因组中,但看着一组三个不同的位置。请帮他算三个不同的位置,都可以解释有斑点集数。
输入
输入的第一行包含N(1≤N≤500)和M(3≤M≤50)。接下来的N行每个字符包含一个字符串;这些描述了斑点奶牛的基因组。最后N行描述了普通奶牛的基因组。
输出
请计算三个不同的位置,可以解释有斑点集数。三个一组的位置说明有斑点如果有斑点的特质可以完美的精确度奶牛的农民约翰的人群,看着那三的位置,在基因组中预测。
样例输入
3 8
aatcccat
gattgcaa
ggtcgcaa
actcccag
actcgcat
acttccat
样例输出
二十二
数据范围限制

思路:
和T2不太一样了
T2是求有多少个位置满足条件,这道是求有几个三元组满足条件
正解是暴力,但有的暴力不一定能过

这是TLE80分的暴力:
代码:

var
        cow:array[0..1000]of string;
        n,m,i,j,k,ans:longint;
procedure solve(x,y,z:longint);
var
        i,j:longint;
        flag:boolean;
        x1,x2,x3:char;
begin
        for i:=1 to n do
        for j:=n+1 to 2*n do
        begin
                if (cow[i][x]=cow[j][x])and(cow[i][y]=cow[j][y])
                and(cow[i][z]=cow[j][z])then exit;
        end;
        inc(ans);
end;
begin
        assign(input,'cownomics.in');reset(input);
        assign(output,'cownomics.out');rewrite(output);
        readln(n,m);
        for i:=1 to 2*n do readln(cow[i]);
        for i:=1 to m do
        for j:=i+1 to m do
        for k:=j+1 to m do
        solve(i,j,k);
        writeln(ans);
        close(input);close(output);
end.

不用想也知道为什么超时:循环大坑

那么怎么用暴力AC本题?
从上面发现,i,j,k三个循环是不可以缺少的
但是有一个1~500循环可以优化
怎么优化?
用一个now数组,记录是否出现过一种方案
省去原先1~500循环的方法是,只用一个1~500循环,同时now记录一下以前是否出现过某种相同的方案,就可以了
提示到这里,应该很好做了
看不懂,我也没办法了,因为我说的已经算很清楚了

代码:

var
        now:array[0..1000]of longint;
        a,b:array[0..1000,0..50]of longint;
        n,m,i,j,k,l,c,d,ans:longint;
        bz:boolean;
        ch:char;
function change(ch:char):longint;
begin
        if ch='A' then exit(1);
        if ch='C' then exit(2);
        if ch='G' then exit(3);
        if ch='T' then exit(4);
end;
procedure readin;
begin
        assign(input,'cownomics.in');reset(input);
        assign(output,'cownomics.out');rewrite(output);
        readln(n,m);
        for i:=1 to n do
        begin
                for j:=1 to m do
                begin
                        read(ch);
                        a[i,j]:=change(ch);
                end;
                readln;
        end;
        for i:=1 to n do
        begin
                for j:=1 to m do
                begin
                        read(ch);
                        b[i,j]:=change(ch);
                end;
                readln;
        end;
end;
begin
        readin;
        for i:=1 to m-2 do
        begin
                for j:=i+1 to m-1 do
                begin
                        for k:=j+1 to m do
                        begin
                                bz:=true;
                                fillchar(now,sizeof(now),0);
                                for l:=1 to n do
                                begin
                                        c:=a[l,i]*100+a[l,j]*10+a[l,k];
                                        d:=b[l,i]*100+b[l,j]*10+b[l,k];
                                        if now[c]=0 then
                                                now[c]:=1
                                        else if now[c]=2 then
                                        begin
                                                bz:=false;
                                                break;
                                        end;
                                        if now[d]=0 then
                                                now[d]:=2
                                        else if now[d]=1 then
                                        begin
                                                bz:=false;
                                                break;
                                        end;
                                end;
                                if bz then inc(ans);
                        end;
                end;
        end;
        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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值