Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-european-regional-contest-neerc-08-en.pdf

此题题意是给你一个单对单密文,让你还原为原文,原文有个性质是,每个单词都是元音和辅音交替组成。

做法是直接5重for,暴力枚举AEIOU分别对应的字母,然后检查,然后输出

详见代码:

//#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include <string.h>

#define MAX_A 26
#define MAX_N 100005
using namespace std;

vector<int> G[MAX_A];

string str[MAX_N];
int n = 0;
string s;

bool g[MAX_A][MAX_A];

int vo[MAX_A];
int tot = 0;
bool flag = 1;

int main() {
    ifstream cin("javanese.in");
    ofstream cout("javanese.out");
    cin.sync_with_stdio(false);
    for (int i = 0; i < 26; i++) {
        if (i != 0 && i != ‘E‘ - ‘A‘ && i != ‘I‘ - ‘A‘ && i != ‘O‘ - ‘A‘ && i != ‘U‘ - ‘A‘)
            vo[tot++] = i;
    }
    while (cin >> s) {
        if (s == "*")break;
        str[n++] = s;
        for (int i = 0; i + 1 < s.length(); i++) {
            int u = s[i] - ‘A‘, v = s[i + 1] - ‘A‘;
            if (u == v)flag = false;
            if (g[u][v])continue;
            G[s[i] - ‘A‘].push_back(s[i + 1] - ‘A‘);
            g[u][v] = 1;
        }
        if (flag == 0) {
            cout << "impossible" << endl;
            return 0;
        }
    }
    int a[5];

    for (a[0] = 0; a[0] < 26; a[0]++)
        for (a[1] = a[0] + 1; a[1] < 26; a[1]++)
            for (a[2] = a[1] + 1; a[2] < 26; a[2]++)
                for (a[3] = a[2] + 1; a[3] < 26; a[3]++)
                    for (a[4] = a[3] + 1; a[4] < 26; a[4]++) {
                        int f[26];
                        memset(f, -1, sizeof(f));
                        int tmp = 0;
                        bool t = 1;
                        for (int i = 0; i < 5 && t; i++)
                            for (int j = 0; j < 5 && t; j++)if (g[a[i]][a[j]])t = 0;
                        if (t == 0)continue;
                        for (int i = 0; i < 26; i++)
                            for (int j = 0; j < 26; j++)
                                if (g[i][j] && i != a[0] && i != a[1] && i != a[2] && i != a[3] && i != a[4] &&
                                    j != a[0] && j != a[1] && j != a[2] && j != a[3] && j != a[4])
                                    t = 0;
                        if (t == 0)continue;
                        for (int i = 0; i < n; i++, cout << " ")
                            for (int j = 0; j < str[i].length(); j++) {
                                int u = str[i][j] - ‘A‘;
                                if (f[u] != -1) {
                                    cout << (char)(f[u] + ‘A‘);
                                    continue;
                                }
                                if (u == a[0])f[u] = ‘A‘ - ‘A‘;
                                else if (u == a[1])f[u] = ‘E‘ - ‘A‘;
                                else if (u == a[2])f[u] = ‘I‘ - ‘A‘;
                                else if (u == a[3])f[u] = ‘O‘ - ‘A‘;
                                else if (u == a[4])f[u] = ‘U‘ - ‘A‘;
                                else f[u] = vo[tmp++];
                                cout << (char)(f[u] + ‘A‘);
                            }
                        cout << endl;
                        return 0;
                    }
    cout << "impossible" << endl;
    return 0;
}
时间: 2024-12-22 09:17:25

Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力的相关文章

codeforces Gym 100286J Javanese Cryptoanalysis

每一单词相邻两个字母,不能同时为元音或者辅音,一定要有五个元音... 各种姿势都可以过:7个for,dp,黑白染色,dfs,并查集.... 最主要的思路就是相邻字母连边 见识到了str = str + str2有多慢 #include<bits/stdc++.h> using namespace std; #define PB push_back int color[26]; int G[26][26]; const int maxn = 1e5+5; char s[maxn]; bool v

Codeforces Gym 100342C Problem C. Painting Cottages 暴力

Problem C. Painting CottagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/attachments Description The new cottage settlement is organized near the capital of Flatland. The construction company that is building the sett

Codeforces Gym 100513I I. Sale in GameStore 暴力

I. Sale in GameStore Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100513/problem/I Description A well-known Berland online games store has announced a great sale! Buy any game today, and you can download more games for free!

Codeforces gym 100685 A. Ariel 暴力

A. ArielTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/A Description King Triton really likes watching sport competitions on TV. But much more Triton likes watching live competitions. So Triton decides to set up

Codeforces Gym 100570 E. Palindrome Query Manacher

E. Palindrome QueryTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100570/problem/E Description De Prezer loves palindrome strings. A string s1s2...sn is palindrome if and only if it is equal to its reverse. De Prezer also love

经典傻逼题

Description 这是一道经典傻逼题,对经典题很熟悉的人也不要激动,希望大家不要傻逼.考虑一张N个点的带权无向图,点的编号为1到N. 对于图中的任意一个点集(可以为空或者全集),所有恰好有一个端点在这个点集中的边组成的集合被称为割. 一个割的权值被定义为所有在这个割上的边的异或和. 一开始这张图是空图,现在,考虑给这张无向图不断的加边,加入每条边之后,你都要求出当前权值最大的割的权值, 注意加入的边永远都不会消失. Input 输入的第一行包括一个数ID表示数据编号, 如第一组数据中的ID

Codeforces gym Hello 2015 Div1 B and Div2 D

Codeforces gym 100571 problem D Problem 给一个有向图G<V,E>和源点S,边的属性有长度L和颜色C,即E=<L,C>.进行Q次询问,每次给定一个点X,输出S到X的最短路的长度(不存在则输出 -1).但要求S到X的路径中相邻两条边颜色不一样. Limits Time Limit(ms): 1000 Memory Limit(MB): 256 |V|, |E|: [1, 10^5] X, S: [1, |V| ] L: [1, 10^9] |C|

Codeforces 6D Lizards and Basements 2 dfs+暴力

题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a

[bzoj4644]经典傻逼题

话说这道题是因为ditoly大佬无聊时候想做sb题搜索了一下"傻逼题"搜到的,刚好今天学习了线性基,在ditoly大佬的帮助下做完啦. ------------------------------------------------------------------------------ 题意:定义割操作是对于原图的一个点集,所有恰好只有一个点在集合中的边的集合,它的权值是所有边的异或和. 给定n个点,m个操作,每次向其中两个点中添加一条边,然后求一个最大的割的权值.n<=5