被自己蠢哭了。。。。

250-point problem

国际象棋棋盘上给出两个坐标,问象从一个走到还有一个最少要几步。

黑格象仅仅能走黑格,白格象仅仅能走白格,仅仅要推断两个坐标的颜色是否同样就能推断是否可达,观察棋盘能够发现坐标的奇偶性决定了格子的颜色;可达的情况下最多两步就能达到,所以仅仅要推断格子是否在同一条斜线上即可了。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm
#define maxn using namespace std; class BishopMove
{
public:
int howManyMoves(int r1, int c1, int r2, int c2)
{
if (r1==r2 && c1==c2) return 0;
if (((r1+c1)&1) == ((r2+c2)&1))
{
if (abs(r1-r2)==abs(c1-c2)) return 1; return 2;
} return -1;
}
}; int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/fcbruce/文档/code/t","r",stdin);
#endif // ONLINE_JUDGE return 0;
}

500-point problem

给出一个括号序列,X可被括号替换,问这串序列是否可能合法。由于当时没看见X的数量不超过5就用了区间DP,有一处下标竟然没控制好结果RE。。。。事实上能够用DFS求出全部可能的序列,然后用栈推断;区间DP仅仅要求出对这段序列最少加多少括号使其合法即可,假设为0就是合法的,要注意对匹配括号的推断。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm
#define maxn using namespace std; class BracketExpressions
{
public:
bool check(char x,char y)
{
if (x=='(' && y==')' || x=='['&& y==']' ||x=='{' && y=='}')
return true; if (x=='X' && (y==']' || y=='}' || y==')' || y=='X')) return true; if (y=='X' && (x=='(' || x=='[' || x=='{')) return true; return false;
}
string ifPossible(string str)
{
int l=str.size(); int dp[60][60];
memset(dp,0,sizeof dp);
for(int i = 0; i<l; i++)
{
dp[i][i] = 1;
} for (int m=1;m<l;m++)
{
for (int i=0;i<l;i++)
{
int j=i+m;
if (j>=l) break;
dp[i][j]=INF;
if (check(str[i],str[j]))
dp[i][j]=min(dp[i][j],dp[i+1][j-1]);
for (int k=i;k<j;k++)
{
dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]);
}
}
} if (dp[0][l-1]==0) return "possible";
else
return "impossible";
}
}; int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/fcbruce/文档/code/t","r",stdin);
#endif // ONLINE_JUDGE return 0;
}

1000-point problem

时间不够,比赛的时候没来得及敲完。。。。。

题意:

给出一个有n个元素的集合E={ x | 0<=x<n , x为整数 },和一段序列f={ xi | 0<=xi,i<n },对于集合E的子集S,有随意i属于S,f[i]=xi 也属于S,问这种子集有多少个。

分析:

这事实上是个图论。

对于每一个i,都相应一个f[i]=xi,假设我取i,那我必然也要取f[i]=xi,即i依赖于f[i]=xi。于是建立有向边i---->f[i]=xi;对于图中的每一个强联通分量,这个分量中的全部点一定是同一时候取的。我们能够进行强联通缩点(tarjan),剩下的DAG中每一个点都有取和不取两种关系。应用乘法原理和加法原理,反向建图后通过树形DP求得最后的方案数:对于节点u,取这个节点的方案数是它全部子节点的方案数相乘,不取这个节点的方案数为1。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<ctime>
#include<cctype>
#include<cmath>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<map>
#include<set>
#define sqr(x) ((x)*(x))
#define LL long long
#define itn int
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
#define eps 1e-10
#define maxm 555555
#define maxn 55 using namespace std; int fir[maxn];
int u[maxm],v[maxm],nex[maxm];
long long w[maxn];
int n; int pre[maxn],low[maxn],sccno[maxn];
int st[maxn],top;
int dfs_clock,scc_cnt; int deg[maxn]; void tarjan_dfs(int _u)
{
pre[_u]=low[_u]=++dfs_clock;
st[++top]=_u;
for (int e=fir[_u];e!=-1;e=nex[e])
{
int _v=v[e];
if (pre[_v]==0)
{
tarjan_dfs(_v);
low[_u]=min(low[_u],low[_v]);
}
else
{
if (sccno[_v]==0)
low[_u]=min(low[_u],pre[_v]);
}
} if (low[_u]==pre[_u])
{
scc_cnt++;
while (true)
{
int x=st[top--];
sccno[x]=scc_cnt;
if (x==_u) break;
}
}
} void find_scc()
{
dfs_clock=scc_cnt=0;
top=-1;
memset(sccno,0,sizeof sccno);
memset(pre,0,sizeof pre);
for (int i=0;i<n;i++)
{
if (pre[i]==0) tarjan_dfs(i);
}
} long long dfs(int _u)
{
long long temp=1;
for (int e=fir[_u];~e;e=nex[e])
{
temp*=dfs(v[e]);
} return temp+1;
} class InvariantSets
{
public:
long long countSets(vector <int> f)
{
n=f.size(); memset(fir,-1,sizeof fir); for (int i=0;i<n;i++)
{
u[i]=i;v[i]=f[i];
nex[i]=fir[i];fir[i]=i;
} find_scc(); memset(fir,-1,sizeof fir);
memset(deg,0,sizeof deg); int e=0; for (int i=0;i<n;i++)
{
if (sccno[u[i]]==sccno[v[i]]) continue; u[e]=sccno[u[i]];v[e]=sccno[v[i]]; swap(u[e],v[e]); nex[e]=fir[u[e]];
deg[v[e]]++;
fir[u[e]]=e++;
} for (int i=1;i<=scc_cnt;i++)
{
if (deg[i]==0)
{
u[e]=i;v[e]=0;
swap(u[e],v[e]);
nex[e]=fir[u[e]];
fir[u[e]]=e++;
}
} return dfs(0)-1; }
}; int main()
{
#ifndef ONLINE_JUDGE
freopen("/home/fcbruce/文档/code/t","r",stdin);
#endif // ONLINE_JUDGE InvariantSets a;
itn x,y;
while (~scanf("%d",&x))
{
vector <int> v;
for (int i=0;i<x;i++)
{
scanf("%d",&y);
v.push_back(y);
} printf("%lld\n",a.countSets(v));
} return 0;
}

Topcoder SRM 628 DIV 2的更多相关文章

  1. TopCoder SRM 560 Div 1 - Problem 1000 BoundedOptimization & Codeforces 839 E

    传送门:https://284914869.github.io/AEoj/560.html 题目简述: 定义"项"为两个不同变量相乘. 求一个由多个不同"项"相 ...

  2. TopCoder SRM 667 Div.2题解

    概览: T1 枚举 T2 状压DP T3 DP TopCoder SRM 667 Div.2 T1 解题思路 由于数据范围很小,所以直接枚举所有点,判断是否可行.时间复杂度O(δX × δY),空间复 ...

  3. [topcoder]SRM 646 DIV 2

    第一题:K等于1或者2,非常简单.略.K更多的情况,http://www.cnblogs.com/lautsie/p/4242975.html,值得思考. 第二题:http://www.cnblogs ...

  4. [topcoder]SRM 633 DIV 2

    第一题,http://community.topcoder.com/stat?c=problem_statement&pm=13462&rd=16076 模拟就可以了. #includ ...

  5. TopCoder SRM 596 DIV 1 250

    body { font-family: Monospaced; font-size: 12pt } pre { font-family: Monospaced; font-size: 12pt } P ...

  6. Topcoder SRM 656 (Div.1) 250 RandomPancakeStack - 概率+记忆化搜索

    最近连续三次TC爆零了,,,我的心好痛. 不知怎么想的,这题把题意理解成,第一次选择j,第二次选择i后,只能从1~i-1.i+1~j找,其实还可以从j+1~n中找,只要没有被选中过就行... [题意] ...

  7. Topcoder SRM 648 (div.2)

    第一次做TC全部通过,截图纪念一下. 终于蓝了一次,也是TC上第一次变成蓝名,下次就要做Div.1了,希望div1不要挂零..._(:зゝ∠)_ A. KitayutaMart2 万年不变的水题. # ...

  8. 【topcoder SRM 702 DIV 2 250】TestTaking

    Problem Statement Recently, Alice had to take a test. The test consisted of a sequence of true/false ...

  9. TopCoder SRM 639 Div.2 500 AliceGameEasy

    题意: 一个游戏有n轮,有A和B比赛,谁在第 i 轮得胜,就获得 i 分,给出x,y,问A得x分,B得y分有没有可能,如果有,输出A最少赢的盘数 解题思路: 首先判断n(n+1)/2 = (x+y)是 ...

随机推荐

  1. C日常语言实践中小(四)——勇者斗恶龙

    勇者斗恶龙 愿你的国有n龙的头,你想聘请骑士杀死它(全部的头). 村里有m个骑士能够雇佣,一个能力值为x的骑士能够砍掉恶龙一个致敬不超过x的头,且须要支付x个金币. 怎样雇佣骑士才干砍掉恶龙的全部头, ...

  2. phonegap+emberjs+python手机店发展,html5实现本地车类别~

    商城开发项目,现在需要做出APP,无奈出场前android但不是很精通.最后选择phonegap实现app. 由于之前办理购物车分为登陆和登陆后两种情况,登录前必须充分利用本地存储.而基于phoneg ...

  3. js防堵塞载入

    js防堵塞载入 <script type="text/javascript"> function scriptDomElement (u) { var s = docu ...

  4. Centos6.5下一个Ceph存储集群结构

    简单的介绍 Ceph的部署模式下主要包括下面几个类型的节点 • Ceph OSDs: A Ceph OSD 进程主要用来存储数据,处理数据的replication,恢复,填充.调整资源组合以及通过检查 ...

  5. c# 判断字符是否是全角, 获取字符串的字节数 , 获取字符串指定长度字节数的字符串

    1 Encoding.Default.GetByteCount(checkString);  =2 全角 =1 半角 /// <summary> /// 获取字符串的字节长度 /// &l ...

  6. 大数据的胖哥的方式(9)- 金融业数据仓库的逻辑模型FS-LDM

    介绍: 大数据是不是海市蜃楼,来自小橡子只是意淫奥克斯,大数据的发展,而且要从头开始,基于大数据建设国家.项目-level数据中心行业将越来越多,大数据仅供技术,而非溶液,临数据组织模式,数据逻辑模式 ...

  7. 存储数据键和项目对的类(Dictionary对象)

    存储数据键和项目对的类(Dictionary对象) <% Class Dictionary Public Copyright, Developer, Name, Version, Web Pri ...

  8. Twitter 新一代流处理工具——Heron 该纸币Storm Limitations

    Twitter 新一代流处理工具--Heron 该纸币Storm Limitations (空格分隔): Streaming-Processing Storm Problems scalability ...

  9. LINQ之路系列文章导读

    本系列文章将会分为3篇来进行阐述,如下: LINQ之路(1):LINQ基础 LINQ之路(2):LINQ to SQL本质 LINQ之路(3):LINQ扩展

  10. JDK自带的监控分析工具JConsole

    非常多开发人员认为自己懂Java编程.事实是大多数开发人员都仅仅领会到了Java平台的皮毛.所学也仅仅够应付工作. 作者将深度挖掘Java平台的核心功能.揭示一些鲜为人知的事实.帮助您解决最棘手的编程 ...