CF593A__2Char

本文介绍了一个算法,用于从一组单词中筛选出使用字母种类不超过两种的文章,以满足特定杂志的投稿要求。该算法通过统计每种可能的字母组合出现的总长度来确定最优选择。
A. 2Char
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.

Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.

Input

The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are nlines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.

Output

Print a single integer — the maximum possible total length of words in Andrew's article.

Sample test(s)
input
4
abb
cacc
aaa
bbb
output
9
input
5
a
a
bcbcb
cdecdecdecdecdecde
aaaa
output
6
Note

In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.

In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.

一道水题:对于每句话,我们首先把它存进set里,利用set去重特性,计算set的size。其余看代码。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;
const int maxn=10000+10;
int main()
{
    int n,vis[150][150];
    set<char> s;
    set<char>::iterator it;
    char ch[1005];
    while(~scanf("%d",&n)) {
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++) {
            scanf("%s",ch);
            for(int j=0;j<strlen(ch);j++) {
                s.insert(ch[j]);
            }
            if(s.size()==1) {
                it=s.begin();
                for(int j='a';j<='z';j++) {
                    if(j==*it) {
                        vis[j][j]+=strlen(ch);
                    }
                    else {
                        vis[j][*it]+=strlen(ch);
                        vis[*it][j]+=strlen(ch);
                    }
                }
            }
            else if(s.size()==2) {
                char a,b;
                it=s.begin();
                a=*it;
                it++;
                b=*it;
                if(a==b) {
                    vis[a][b]+=strlen(ch);
                }
                else {
                    vis[a][b]+=strlen(ch);
                    vis[b][a]+=strlen(ch);
                }
            }
            s.clear();
        }
        int MAX=-1;
        for(int i='a';i<='z';i++) {
            for(int j='a';j<='z';j++) {
                if(MAX<vis[i][j]) {
                    MAX=vis[i][j];
                }
            }
        }
        printf("%d\n",MAX);
    }
    return 0;
}


module vga_char( clk,rst_n, hsync,vsync,vga_r,vga_g,vga_b ); input clk; input rst_n; output hsync; output vsync; output[3:0] vga_r; output[3:0] vga_g; output[3:0] vga_b; reg[9:0]x_cnt; reg[9:0]y_cnt; reg clk_vga=0; reg clk_cnt=0; always@(posedge clk or negedge rst_n)begin if(!rst_n) clk_vga<=1'b0; else if(clk_cnt==1)begin clk_vga<=~clk_vga; clk_cnt<=0; end else clk_cnt<=clk_cnt+1; end reg valid_yr; always@(posedge clk_vga or negedge rst_n)begin if(!rst_n)valid_yr<=1'b0; else if(y_cnt==10'd32)valid_yr<=1'b1; else if(y_cnt==10'd511)valid_yr<=1'b0; end wire valid_y=valid_yr; reg valid_r; always@(posedge clk_vga or negedge rst_n)begin if(!rst_n)valid_r<=1'b0; else if((x_cnt==10'd141)&&valid_y)valid_r<=1'b1; else if((x_cnt==10'd781)&&valid_y)valid_r<=1'b0; end wire valid=valid_r; always@(posedge clk_vga or negedge rst_n)begin if(!rst_n) x_cnt<=10'd0; else if(x_cnt==10'd799) x_cnt<=10'd0; else x_cnt<= x_cnt+1'b1; end always@(posedge clk_vga or negedge rst_n)begin if(!rst_n) y_cnt <= 10'd0; else if(y_cnt == 10'd524) y_cnt <= 10'd0; else if(x_cnt == 10'd799) y_cnt <= y_cnt+ 1'b1; end reg hsync_r,vsync_r; always @(posedge clk_vga or negedge rst_n)begin if(!rst_n) hsync_r<= 1'b1; else if(x_cnt == 10'd0) hsync_r<=1'b0; else if(x_cnt == 10'd96)hsync_r<= 1'b1; end always @(posedge clk_vga or negedge rst_n)begin if(!rst_n) vsync_r<= 1'b1; else if(y_cnt == 10'd0) vsync_r<= 1'b0; else if(y_cnt == 10'd2) vsync_r<= 1'b1; end assign hsync = hsync_r; assign vsync = vsync_r; wire[9:0] x_dis; wire[9:0] y_dis; assign x_dis = x_cnt - 10'd142; assign y_dis = y_cnt - 10'd33; parameter char_line00 = 128'hFFFFFFC07FFC00001FFF0000007C0000, char_line01 = 128'hFFFFFFC07FFE00003FFF800000FE0000, char_line02 = 128'hFFFFFFC07FFF00007FFFC00001CF0000, char_line03 = 128'hFFFFFFC0783F8000FE0FE00001CF0000, char_line04 = 128'hFFFFFFC0780FC001FC07F00003CF8000, char_line05 = 128'hF80000007807E003F803F00003878000, char_line06 = 128'hF80000007803F007F001F0000787C000, char_line07 = 128'hF80000007801F007F00000000703C000, char_line08 = 128'hF80000007800F007E00000000F03E000, char_line09 = 128'hF80000007800F007C00000000E01E000, char_line0a = 128'hF80000007800F007800000001E01F000, char_line0b = 128'hF80000007801F0078FFFFF001C00F000, char_line0c = 128'hF80000007803F0078FFFFF003C00F800, char_line0d = 128'hF80000007807F0078FFFFF0038007800, char_line0e = 128'hF8000000780FE0078FFFFF0078007C00, char_line0f = 128'hFFFFE000781FC0078007C0007FFFFC00, char_line10 = 128'hFFFFE000783F80078007C000FFFFFE00, char_line11 = 128'hFFFFE0007FFF00078007C000FFFFFE00, char_line12 = 128'hF80000007FFE00078007C001F8003F00, char_line13 = 128'hF80000007FFC00078007C001F8003F00, char_line14 = 128'hF8000000780000078007C003F8003F80, char_line15 = 128'hF8000000780000078007C003F0001F80, char_line16 = 128'hF800000078000007C00FC003E0000F80, char_line17 = 128'hF800000078000007E01FC003C0000780, char_line18 = 128'hF800000078000007F03FC003C0000780, char_line19 = 128'hF800000078000007F87FC003C0000780, char_line1a = 128'hF800000078000003FFFFC003C0000780, char_line1b = 128'hF800000078000001FFFFC003C0000780, char_line1c = 128'hF800000078000000FFFFC003C0000780, char_line1d = 128'hF8000000780000007FFF8003C0000780, char_line1e = 128'hF8000000780000003FFF0003C0000780, char_line1f = 128'hF8000000780000001FFE0007F0001FC0; reg[6:0] char_bit; always @(posedge clk_vga or negedge rst_n) if(!rst_n) char_bit<= 7'h7f; else if(x_cnt==10'd400)char_bit<=7'd128; else if(x_cnt>10'd400 &&x_cnt<10'd528)char_bit<=char_bit-1'b1; reg[11:0] vga_rgb; always @(posedge clk_vga) begin if(!valid) vga_rgb<= 11'b0000_0000_0000; else if(x_cnt> 10'd400 &&x_cnt < 10'd528) begin case(y_dis) 10'd200:if(char_line00[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd201:if(char_line01[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd202:if(char_line02[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd203:if(char_line03[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd204:if(char_line04[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd205:if(char_line05[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd206:if(char_line06[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd207:if(char_line07[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd208:if(char_line08[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd209:if(char_line09[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd210:if(char_line0a[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd211:if(char_line0b[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd212:if(char_line0c[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd213:if(char_line0d[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd214:if(char_line0e[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd215:if(char_line0f[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd216:if(char_line10[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd217:if(char_line11[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd218:if(char_line11[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd219:if(char_line13[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd220:if(char_line14[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd221:if(char_line15[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd222:if(char_line16[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd223:if(char_line17[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd224:if(char_line18[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd225:if(char_line19[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd226:if(char_line1a[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd227:if(char_line1b[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd228:if(char_line1c[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd229:if(char_line1d[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd230:if(char_line1e[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; 10'd231:if(char_line1f[char_bit]) vga_rgb<= 11'b1111_1111_1111; else vga_rgb<= 11'b000_0000_0000; default: vga_rgb <= 11'h000; endcase end else vga_rgb <= 11'h000; end assign vga_r = vga_rgb[11:8]; assign vga_g = vga_rgb[7:4]; assign vga_b = vga_rgb[3:0]; endmodule 将代码改成白底黑字显示
06-17
已经博主授权,源码转载自 https://pan.quark.cn/s/a4b39357ea24 常见问题解答 网页打开速度慢或者打不开网页? 受到多种因素的影响,对于非会员用户我们无法提供最优质的服务。 如果您希望得到最棒的体验,请至大会员页面("右上角菜单 → 大会员")根据说明操作。 请注意:受制于国际网络的诸多不确定性,我们无法对任何服务的可靠性做出任何保证。 如果出现了网络连接相关的问题,我们建议您先等待一段时间,之后再重试。 如果您在重试后发现问题仍然存在,请联系我们,并说明网络问题持续的时间。 图片下载后无法找到? 打开"右上角菜单 → 更多 → 修改下载路径",在弹出的对话框中可以看到当前图片的保存路径。 此外,由于网络因素,在保存图片之后,等待屏幕下方出现"已保存到..."后,才能在本地找到图片。 如何更改图片保存的目录? 请参见"右上角菜单 → 更多 → 修改下载路径"。 翻页不方便? 在点进某个图片后,通过在图片上向左或向右滑动,即可翻页查看下一个作品。 如何保存原图/导出动图? 长按图片/动图,在弹出的菜单中选择保存/导出即可。 输入账号密码后出现"进行人机身份验证"? 此为pixiv登陆时的验证码,请按照要求点击方框或图片。 在pxvr中注册pixiv账号后,收到验证邮件,无法访问邮件中的验证链接? 请复制邮件中的链接,打开pxvr中的"右上角菜单 → 输入地址"进行访问。 能否自动将页面内容翻译为汉语? 很抱歉,pxvr暂不提供语言翻译服务。 图片下载类型是否可以选择? 能否批量下载/批量管理下载? 已支持批量下载多图作品中的所有原图:找到一个多图作品,进入详情页面后,点击图片进入多图浏览模式,长按任意一张图片即可看到批量下载选项。 关于上述其他功能,我们...
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值