我果然是题短了就能做得好- -。Div 2的三道题都短,于是迅速的过掉了250和500,rating涨了150^ ^。

Div 2 250pt

题意:给一个vector<int> A,对其中任意的数x,可以将其变为2^t * x(t为正整数),判断能不能将A变为所有数全部一样。

解法:我的方法是,将A排序,对第i个,while(A[i] < A[i+1]) A[i] *= 2,如果最终A[i] != A[i+1],则答案为不能。若对所有的i都可以,则答案为能。

水题就不贴代码了。

Div 2 500pt/ Div 1 250pt

题意:给两个等长的字符串s1和s2,对s1进行操作,每次操作能将s1中某个字符提前到s1中的第一个。问最少进行多少次操作,能将s1变成s2。若不能返回-1。  

解法:首先,对s1和s2所含字符的数量进行统计,判断能不能将s1变为s2。

   然后,改变后的s1有两种字符,被操作过的字符全部在s1的前部分,没被操作过的字符全部在s1的后部分,而且,对于后部分的字符,相对顺序在s1改变前后并没有改变。

   所以,从后往前用i枚举s1的所有字符,同时置一个idx对s2从后往前移动。if (s1[i] == s2[idx]) {-- i; -- idx} else -- i;

   这样,idx+1即为答案。

tag:greedy

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "LittleElephantAndString.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring> using namespace std; #define CLR(x) memset(x, 0, sizeof(x))
#define PB push_back char a[], b[];
int num[][]; class LittleElephantAndString
{
public:
int getNumber(string A, string B){
char x = 'A'; int n = A.size();
for (int i = , j = n-; j >= ; ++ i, -- j){
a[i] = A[j];
b[i] = B[j];
} CLR (num);
for (int i = ; i <= n; ++ i){
num[a[i]-x][] ++;
num[b[i]-x][] ++;
} for (int i = ; i < ; ++ i)
if (num[i][] != num[i][]) return -; int cnt = n - ;
for (int i = n-; i >= ; -- i){
if (A[i] == B[cnt])
-- cnt;
}
if (cnt == n-) return -;
return cnt+;
}
};

Div2 1000pt

题意:给定一个数n,称这样的集合为关于n的好集合:所有元素的值均在n以内,且将所有元素写在黑板上,所需要写的0, 1, 2..9的次数均不超过1次。给定n求好数组的数量。(n <= 10^9),答案关于1000000007取模。

解法:对于任意给定的数n,首先用dfs求出所有能被放在关于n的好集合中的数,并将他们分好类。分类的方法为,对于数k,将它写在黑板上需要写的数字有a0, a1, a2..at,则它属于类((0 | 1<<a0) | (1<<a1) | ... | (1<<at))。比如1属于类2,10属于类3,123属于类14。

   分好类之后,就发现,同一个集合之中,最多一个能出现在关于n的好集合中,且不同集合的数也不一定能同时出现在关于n的好集合中,比如类2和类3(因为都含有1)。

   这样的话,就变成了一个01背包问题。设d[i][j]表示前i类中去数,状态为j的情况下能有多少好集合。

   注意到,此处第i类所代表的状态也为i,所以状态转移方程为d[i][i|j] += d[i-1][j] * num(类i)。num(类i)表示类i中含有元素的个数。

tag:dp, 背包, good

 // BEGIN CUT HERE
/*
* Author: plum rain
* score :
*/
/* */
// END CUT HERE
#line 11 "LittleElephantAndSubset.cpp"
#include <sstream>
#include <stdexcept>
#include <functional>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <cctype>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
//#include <cmath>
//#include <algorithm>
//#include <cstdlib>
//#include <set>
//#include <queue>
//#include <bitset>
//#include <list>
//#include <string>
//#include <utility>
//#include <map>
//#include <ctime>
//#include <stack> using namespace std; #define CLR(x) memset(x, 0, sizeof(x))
#define PB push_back
//#define SZ(v) ((int)(v).size())
//#define zero(x) (((x)>0?(x):-(x))<eps)
//#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-8;
//const double PI = atan(1.0)*4;
//const int maxint = 2139062143;
const int64 mod = ;
// int n, num;
bool vis[], opt[];
int64 d[<<];
vector<int> a[]; int64 max64(int64 a, int64 b)
{
return a > b ? a : b;
} void dfs(int x, int p)
{
int64 y = (int64)x * + p;
if (y > n) return; int sta = ;
for (int i = ; i <= ; ++ i)
if (vis[i]) sta |= ( << i);
a[sta].PB((int)y); for (int i = ; i <= ; ++ i) if(!vis[i]){
vis[i] = ;
dfs((int)y, i);
vis[i] = ;
}
} bool ok(int a, int b)
{
for (int i = ; i < ; ++ i){
int t1 = a & ( << i), t2 = b & ( << i);
if (t1 && t2) return ;
}
return ;
} class LittleElephantAndSubset
{
public:
int getNumber(int N){
n = N; num = << ;
for (int i = ; i < num; ++ i)
a[i].clear();
CLR (vis); for (int i = ; i <= ; ++ i){
vis[i] = ;
dfs(, i);
vis[i] = ;
} CLR (d);
for (int i = ; i < num; ++ i){
if (a[i].size()) d[i] = (a[i].size() + d[i]) % mod;
for (int j = num-; j >= ; -- j) if (ok(i, j))
d[i|j] = ((d[j]%mod) * ((int64)a[i].size()%mod) + d[i|j]) % mod;
} int ret = ;
for (int i = ; i < num; ++ i)
ret = (d[i] + ret) % mod;
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(); if ((Case == -) || (Case == )) test_case_3(); }
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() { int Arg0 = ; int Arg1 = ; verify_case(, Arg1, getNumber(Arg0)); }
void test_case_1() { int Arg0 = ; int Arg1 = ; verify_case(, Arg1, getNumber(Arg0)); }
void test_case_2() { int Arg0 = ; int Arg1 = ; verify_case(, Arg1, getNumber(Arg0)); }
void test_case_3() { int Arg0 = ; int Arg1 = ; verify_case(, Arg1, getNumber(Arg0)); } // END CUT HERE }; // BEGIN CUT HERE
int main()
{
freopen( "a.out" , "w" , stdout );
LittleElephantAndSubset ___test;
___test.run_test(-);
return ;
}
// END CUT HERE

SRM 597的更多相关文章

  1. TC SRM 597 DEV2

    第一次玩TC的SRM,只完成了一题,有点失落,不过还是要把每个问题都研究清楚才是我的本性,呵呵 第一题思路: 任意一个数,不断除掉2以后的剩下的数若相同则YES否则NO 第二题: 最开始判断字母个数是 ...

  2. Topcoder SRM 597

    妈蛋第一场tc就掉分,提交了第一个题的时候就注定悲剧要发生了,妈蛋没考虑0就直接%了,真的是人傻见识又少,第二题最后有了一点思路,没时间写了,可能也不是很准确,第三题想了小会儿效果为0! 然后第一题傻 ...

  3. Topcoder口胡记 SRM 562 Div 1 ~ SRM 599 Div 1

    据说做TC题有助于提高知识水平? :) 传送门:https://284914869.github.io/AEoj/index.html 转载请注明链接:http://www.cnblogs.com/B ...

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

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

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

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

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

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

  7. SRM 657 DIV2

    -------一直想打SRM,但是感觉Topcoder用起来太麻烦了.题目还是英文,不过没什么事干还是来打一打好了.但是刚注册的号只能打DIV2,反正我这么弱也只适合DIV2了.. T1: 题目大意: ...

  8. nyist 597 完数?

    http://acm.nyist.net/JudgeOnline/problem.php?pid=597 完数? 时间限制:1000 ms  |  内存限制:65535 KB 难度:1   描述 一个 ...

  9. SRM DIV1 500pt DP

    SRM 501 DIV1 500pt SRM 502 DIV1 500pt SRM 508 DIV1 500pt SRM 509 DIV1 500pt SRM 511 DIV1 500pt SRM 5 ...

随机推荐

  1. jQuery实现页面滚动时顶部动态显示隐藏

    http://www.jqcool.net/jquery-scroll.html 另外headroom.js也行:http://www.bootcss.com/p/headroom.js/

  2. Android布局管理器(表格布局)

    表格布局有TableLayout所代表,TableLayout继承了LinearLayout,因此他的本质依然是LinearLayout. 表格布局采用行.列的形式来进行管理,在使用的时候不需要声明多 ...

  3. 受限玻尔兹曼机(RBM)

    能量模型 RBM用到了能量模型. 简单的概括一下能量模型.假设一个孤立系统(总能量$E$一定,粒子个数$N$一定),温度恒定为1,每个粒子有$m$个可能的状态,每个状态对应一个能量$e_i$.那么,在 ...

  4. IOS 多线程,线程同步的三种方式

    本文主要是讲述 IOS 多线程,线程同步的三种方式,更多IOS技术知识,请登陆疯狂软件教育官网. 一般情况下我们使用线程,在多个线程共同访问同一块资源.为保护线程资源的安全和线程访问的正确性. 在IO ...

  5. iOS菜鸟之FMDB的二次封装简单易用

    闲来无事写点东西,希望大家多多指正! 大家先去git下载FMDB,然后将其中source文件夹中的fmdb文件夹拖入自己的项目中.最后就可以引用下面的代码对fmdb进行一次简单的封装. 这样可以更直观 ...

  6. Xcode4.4中,代码无法高亮、无法自动补全

    1.代码无法高亮显示:2.代码不能自动补全,或者给出提示建议:(当然这个补全的功能我在设置当中是打开的状态)3.新建一个项目,代码还是依然没有高亮显示,但是有补全功能:4.然后我就在网络上搜索了相关的 ...

  7. @import————————css代码内部链接另外css

    在css代码里这样可以链接另外的css @import url("style.css");   @import语法结构 @import + 空格+ url(CSS文件路径地址); ...

  8. Python--模块微谈

    一个.py文件是一个模块,模块里面可以定义很多函数,载入模块就可以使用函数.模块又有python内置模块,又有第三方模块,不同模块里可以有相同的函数名和变量名,模块又可以组织到package里,不同的 ...

  9. WWDC2014之iOS使用动态库

    苹果的开放态度 WWDC2014上发布的Xcode6 beta版有了不少更新,其中令我惊讶的一个是苹果在iOS上开放了动态库,在Xcode6 Beta版的更新文档中是这样描述的: Frameworks ...

  10. cloudera-scm-server ip改了怎么办了

    1.vi /etc/cloudera-scm-agent/config.ini #改下ip 2.manager 老只看到一个主机 rm -f /var/lib/cloudera-scm-agent/u ...