早早地水完了三道题,pt1000用的是dfs,开始做的时候误认为复杂度最多就O(2^25),结果被一组O(2*3^16)的数据接近1e8给cha了。继续努力。

pt250:求两个串的前缀组成的不同串数目。set搞定。

 /*
*Author: Zhaofa Fang
*Created time: 2013-07-10-18.54
*Language: C++
*/
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std; typedef long long ll;
#define DEBUG(x) cout<< #x << ':' << x << endl
#define FOR(i,s,t) for(int i = (s);i <= (t);i++)
#define FORD(i,s,t) for(int i = (s);i >= (t);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPD(i,n) for(int i=(n-1);i>=0;i--)
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define lowbit(x) (x&(-x))
#define INF (1<<30)
#define eps 1e-8 class TopFox{
public :
int possibleHandles(string f, string g){
set<string>S;
int lenf = f.length();
int leng = g.length();
REP(i,lenf){
REP(j,leng){
string tmp = "";
REP(k,i+)tmp += f[k];
REP(k,j+)tmp += g[k];
S.insert(tmp);
}
}
return S.size();
}
};

250

pt500:给定一幅图的连接情况,要求相邻两个点的差不大于d,求点之间的最大差。

    可以对每个点进行bfs,比较直观。也有一些人用的是floyd,道理一样的。

 /*
*Author: Zhaofa Fang
*Created time: 2013-07-10-18.54
*Language: C++
*/
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std; typedef long long ll;
#define DEBUG(x) cout<< #x << ':' << x << endl
#define FOR(i,s,t) for(int i = (s);i <= (t);i++)
#define FORD(i,s,t) for(int i = (s);i >= (t);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPD(i,n) for(int i=(n-1);i>=0;i--)
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define lowbit(x) (x&(-x))
#define INF (1<<30)
#define eps 1e-8 class Egalitarianism{
public :
bool vist[];
int mon[];
bool OK;
int bfs(int s,vector <string> isFriend, int d){
int n = isFriend.size();
queue<int>Q;
Q.push(s);
int ans = -;
memset(vist,,sizeof(vist));
mon[s] = ;
vist[s] = ;
while(!Q.empty()){
int now = Q.front();
Q.pop();
REP(i,n){
if(isFriend[now][i] == 'Y' && !vist[i]){
Q.push(i);
mon[i] = mon[now] + d;
vist[i] = ;
ans = max(ans,mon[i]);
}
}
}
REP(i,n)if(!vist[i])return -;
return ans;
}
int maxDifference(vector <string> isFriend, int d){
int n = isFriend.size();
int ans = -;
REP(i,n)ans = max(bfs(i,isFriend,d),ans);
return ans;
}
};

500

pt1000:给定一组数kind[],从中取K个,取得的数为found[],能有多少种可能。其中一组sample如下:

{1, 2, 1, 1, 2, 3, 4, 3, 2, 2}
{4, 2}
3
Returns: 6
The archeologist excavated one of six possible triples of building sites:

  • (1, 4, 6)
  • (1, 6, 8)
  • (1, 6, 9)
  • (4, 6, 8)
  • (4, 6, 9)
  • (6, 8, 9)

  正解dp。很简单的转移-__-。

 /*
*Author: Zhaofa Fang
*Created time: 2013-07-10-18.54
*Language: C++
*/
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std; typedef long long ll;
#define DEBUG(x) cout<< #x << ':' << x << endl
#define FOR(i,s,t) for(int i = (s);i <= (t);i++)
#define FORD(i,s,t) for(int i = (s);i >= (t);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPD(i,n) for(int i=(n-1);i>=0;i--)
#define PII pair<int,int>
#define PB push_back
#define MP make_pair
#define ft first
#define sd second
#define lowbit(x) (x&(-x))
#define INF (1<<30)
#define eps 1e-8 ll C[][]; void pre(){
C[][] = C[][] = ;
FOR(i,,){
C[i][] = ;
FOR(j,,i)C[i][j] = C[i-][j-] + C[i-][j];
}
}
class Excavations2{
public :
int ff[];
ll dp[][];
ll count(vector <int> kind, vector <int> found, int K){
pre();
int len = kind.size();
memset(ff,,sizeof(ff));
REP(i,len)ff[kind[i]]++;
memset(dp,,sizeof(dp));
int n = found.size();
FOR(i,,ff[found[]]){
dp[][i] = C[ff[found[]]][i];
}
FOR(i,,n){
FOR(j,,K){
FOR(k,,ff[found[i-]])
dp[i][j] += dp[i-][j-k]*C[ff[found[i-]]][k];
}
}
return dp[n][K];
}
}; //int main(){
// //freopen("in","r",stdin);
// //freopen("out","w",stdout);
//
// return 0;
//}

1000

SRM 584 div2的更多相关文章

  1. TC SRM 584 DIV2

    250pt: 水题set处理. 500pt: 题意: 给你一个图,每条边关联的两点为朋友,题目要求假设x的金钱为y,则他的左右的朋友当中的钱数z,取值为y - d <= z <= y + ...

  2. SRM 657 DIV2

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

  3. Topcoder Srm 673 Div2 1000 BearPermutations2

    \(>Topcoder \space Srm \space 673 \space Div2 \space 1000 \space BearPermutations2<\) 题目大意 : 对 ...

  4. Topcoder Srm 671 Div2 1000 BearDestroysDiv2

    \(>Topcoder \space Srm \space 671 \space Div2 \space 1000 \space BearDestroysDiv2<\) 题目大意 : 有一 ...

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

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

  6. TC SRM 584 DIV 2

    第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...

  7. Topcoder srm 632 div2

    脑洞太大,简单东西就是想复杂,活该一直DIV2; A:水,基本判断A[I]<=A[I-1],ANS++; B:不知道别人怎么做的,我的是100*N*N;没办法想的太多了,忘记是连续的数列 我们枚 ...

  8. SRM 584 第一次玩TopCoder。。。只水题一道。。。

    第一次topcoder,以前老感觉没有资格去做tc,cf什么的,现在已经慢慢接触了. 感觉还可以,还是有让我们这些蒻菜安慰的水题. tc的确很好玩,用客户端比赛,还有各种规则,而且还是只编写一个类提交 ...

  9. SRM 638 Div2

    2333... 因为TC过少的参与者.加上不断fst 我掉了div2该. 幸运的是完成的背div1该.. 250 水的问题 500 水的问题.. 直接bfs扩展即可了 注意判重.  我还用康托展开了真 ...

随机推荐

  1. getHibernateTemplate().find()

    find(String queryString, Object[] values); 这个方法后者的参数必须是一个数组,而不能是一个List. List ul=getHibernateTemplate ...

  2. delphi 打开文件夹并定位到一个文件(使用ShellExecute时加一个select参数,原来这么简单!)

    strFileName := FcxLV[nIndex].Items.Item[FcxLV[nIndex].ItemIndex].SubItems.Strings[0]; //路径  ShellExe ...

  3. poj3650---将一个字符串中的特定字符转换

    #include <stdio.h> #include <stdlib.h> #include<string.h> int main() { ]; int i; w ...

  4. #include <locale.h> #include <locale>

    C C++ C 1 setlocale setlocale,本函数用来配置地域的信息,设置当前程序使用的本地化信息. #include <stdio.h> #include <std ...

  5. iOS 开发常用设置

    1. iOS设置app应用程序文件共享 设置流程 xcode 打开项目----在 info.plist 文件,添加 UIFileSharingEnabled 并设置属性为 YES, 在app内部,将您 ...

  6. iOS开发中视图相关的小笔记:push、modal、popover、replace、custom

    在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的. 在iphone中,segue有:push,modal,和custom三种不同的类型, ...

  7. Linux下装Eclipse C/C++,以及环境配置

    由于前些日子朋友搞个智能家居开发,用C语言写的.叫我装个CentOS(Linux中的一种)来进行开发,所以这几天都在摸索怎么装,当然,朋友也有给予一丁点帮助(可恶的色长.你叫我装东西,也不帮帮我),由 ...

  8. 网上B2C书城,1.0javaWEB版!!好几天没更新了,都忙着做那个网站了~

    惯例帮师傅打个广告www.java1234.com,从基础学习java WEB! 从最初的构思,到一点点功能的实现,真是不容易啊,由于自己没有项目经验,完全依靠自己的感觉,以及自己琢磨出来的思路来写, ...

  9. iOS判断并使用百度地图 高德地图 导航 (使用URI,不集成sdk)

    [objc] view plaincopy  1. BOOL hasBaiduMap = NO;   2.         BOOL hasGaodeMap = NO;   3.            ...

  10. JVM学习之内存分配一

    转自:http://blog.csdn.net/mazhimazh/article/details/16879055,多谢博主分享 我们知道计算机的基本构成是:运算器.控制器.存储器.输入和输出设备, ...