DIV1 250pt

题意:给两个'a'-'z'的字符串,是否存在一个'a'-'z'的置换,使得能将一个字符串转化成另一个字符串。

解法:题意即是求,s1和s2对应位置出现的字符在原字符串中出现的次数和每次出现的位置是否一样。可以将s1和s2分别转化成一个数列,数列的相等与否 和 是否存在那样的置换是等价的。

tag:think

 // BEGIN CUT HERE
/* */
// END CUT HERE
#line 7 "IsomorphicWords.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <set>
#include <queue>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <string>
#include <utility>
#include <map>
#include <ctime>
#include <stack> using namespace std; #define clr0(x) memset(x, 0, sizeof(x))
#define clr1(x) memset(x, -1, sizeof(x))
#define pb push_back
#define sz(v) ((int)(v).size())
#define out(x) cout<<#x<<":"<<(x)<<endl
#define tst(a) cout<<#a<<endl
#define CINBEQUICKER std::ios::sync_with_stdio(false) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64; const double eps = 1e-;
const double PI = atan(1.0)*;
const int inf = / ; inline int MyMod( int a , int b ) { return (a%b+b)%b;} void gao(string a, int *num)
{
int n = sz(a);
map<char, int> mp; mp.clear();
int cnt = ;
for (int i = ; i < n; ++ i){
if (!mp.count(a[i])){
mp[a[i]] = cnt; num[i] = cnt ++;
}
else num[i] = mp[a[i]];
}
} bool ok(string a, string b)
{
int n1[], n2[];
clr0 (n1); clr0 (n2);
gao(a, n1); gao(b, n2);
for (int i = ; i < ; ++ i)
if (n1[i] != n2[i]) return ;
return ;
} class IsomorphicWords
{
public:
int countPairs(vector <string> v){
int ret = ;
for (int i = ; i < sz(v); ++ i)
for (int j = i+; j < sz(v); ++ j)
if (ok(v[i], v[j])) ++ ret;
return ret;
} // BEGIN CUT HERE
public:
void run_test(int Case) { if ((Case == -) || (Case == )) test_case_0(); if ((Case == -) || (Case == )) test_case_1(); if ((Case == -) || (Case == )) test_case_2(); }
private:
template <typename T> string print_array(const vector<T> &V) { ostringstream os; os << "{ "; for (typename vector<T>::const_iterator iter = V.begin(); iter != V.end(); ++iter) os << '\"' << *iter << "\","; os << " }"; return os.str(); }
void verify_case(int Case, const int &Expected, const int &Received) { cerr << "Test Case #" << Case << "..."; if (Expected == Received) cerr << "PASSED" << endl; else { cerr << "FAILED" << endl; cerr << "\tExpected: \"" << Expected << '\"' << endl; cerr << "\tReceived: \"" << Received << '\"' << endl; } }
void test_case_0() { string Arr0[] = {"abca", "zbxz", "opqr"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, countPairs(Arg0)); }
void test_case_1() { string Arr0[] = {"aa", "ab", "bb", "cc", "cd"}; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, countPairs(Arg0)); }
void test_case_2() { string Arr0[] = { "cacccdaabc", "cdcccaddbc", "dcdddbccad", "bdbbbaddcb",
"bdbcadbbdc", "abaadcbbda", "babcdabbac", "cacdbaccad",
"dcddabccad", "cacccbaadb", "bbcdcbcbdd", "bcbadcbbca" }; vector <string> Arg0(Arr0, Arr0 + (sizeof(Arr0) / sizeof(Arr0[]))); int Arg1 = ; verify_case(, Arg1, countPairs(Arg0)); } // END CUT HERE };
//by plum rain
// BEGIN CUT HERE
int main()
{
//freopen( "a.out" , "w" , stdout );
IsomorphicWords ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 391(1-250pt)的更多相关文章

  1. SRM593(1-250pt,500pt)

    SRM 593 DIV1 250pt 题意:有如下图所示的平面,每个六边形有坐标.将其中一些六边形染色,要求有边相邻的两个六边形不能染同一种颜色.给定哪些六边形需要染色,问最少需要多少种颜色. 解法: ...

  2. SRM475 - SRM479(1-250pt,500pt)

    SRM 475 DIV1 300pt 题意:玩游戏.给一个棋盘,它有1×n(1行n列,每列标号分别为0,1,2..n-1)的格子,每个格子里面可以放一个棋子,并且给定一个只含三个字母WBR,长度为n的 ...

  3. SRM468 - SRM469(1-250pt, 500pt)

    SRM 468 DIV1 250pt 题意:给出字典,按照一定要求进行查找. 解法:模拟题,暴力即可. tag:water score: 0.... 这是第一次AC的代码: /* * Author: ...

  4. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

  5. SRM 609(1-250pt, 1-500pt)

    嗯....还是应该坚持写题解的好习惯啊... DIV1 250pt 这难度是回到srm 300+的250了嘛...略 // BEGIN CUT HERE /* * Author: plum rain ...

  6. SRM 442(1-250pt, 1-500pt)

    DIV1 250pt 题意:将一个数表示成质因子相乘的形式,若乘式所含数字的个数为质数,则称A为underprime.比如12 = 2*2*3,则含3个数字,是underprime.求A, B之间un ...

  7. 记第一次TopCoder, 练习SRM 583 div2 250

    今天第一次做topcoder,没有比赛,所以找的最新一期的SRM练习,做了第一道题. 题目大意是说 给一个数字字符串,任意交换两位,使数字变为最小,不能有前导0. 看到题目以后,先想到的找规律,发现要 ...

  8. SRM 513 2 1000CutTheNumbers(状态压缩)

    SRM 513 2 1000CutTheNumbers Problem Statement Manao has a board filled with digits represented as St ...

  9. SRM 510 2 250TheAlmostLuckyNumbersDivTwo(数位dp)

    SRM 510 2 250TheAlmostLuckyNumbersDivTwo Problem Statement John and Brus believe that the digits 4 a ...

随机推荐

  1. Android 通信机制Message、Handler 的用法

    Android中提供了通信机制,Message.Handler 等,Message用于在子线程中传递数据,Handler用于发送数据到主线程中, 下面介绍基于Message.Handler的计时器 i ...

  2. 初试ubuntu14.4问题集锦2

    好的,我开始继续鼓捣. 想了这么长时间,我想到的是,肯定是compiz设置了unity的什么东西才导致这种问题,绝非什么显卡驱动的事情. 于是二话不说,开机登录,进入tty1,然后apt-get re ...

  3. stat 的名字接口

    File::stat - stat 的名字接口 名字为:dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, blksiz ...

  4. 用Python高亮org-mode代码块

    文章同时可在我的github blog上阅读:http://cheukyin.github.io/python/2014-08/pygments-highlight-src-export-html.h ...

  5. JS作用域概念-预解析规则

    // 作用域: // 域:空间.范围.区域…… // 作用:读.写 script 全局变量.全局函数 自上而下 函数 由里到外 {} 浏览器: “JS解析器” 1)“找一些东西” :var funct ...

  6. Easyui的combobox组件无法选择内容

    我切换combobox的内容的时候,老是选中的是第一行的数据,因为我渲染的时候没有给它valueField和textField的字段,而默认的又不是我要求的. 加上就好了. $("#tool ...

  7. JQuery对单选框,复选框,下拉菜单的操作

    JSP <%@ page language="java" import="java.util.*" pageEncoding="utf-8&qu ...

  8. 使用Slip.js快速创建整屏滑动的手机网页

    原文  http://segmentfault.com/blog/laopopo/1190000000708417 现在滑屏网页越来越多,比如我在搜狐视频就做了好几个,举个例子,可以用手机扫描以下的二 ...

  9. GPUImage 自定义滤镜

    GPUImage 自定义滤镜 GPUImage 是一个基于 GPU 图像和视频处理的开源 iOS 框架.由于使用 GPU 来处理图像和视频,所以速度非常快,它的作者 BradLarson 称在 iPh ...

  10. 转:Gulp使用指南

    原文来自于:http://www.techug.com/gulp Grunt靠边,全新的建构工具来了.Gulp的code-over-configuration不只让撰写任务(tasks)更加容易,也更 ...