被自己蠢哭了。。。。

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 maxnusing 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_JUDGEfreopen("/home/fcbruce/文档/code/t","r",stdin);#endif // ONLINE_JUDGEreturn 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 maxnusing 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";elsereturn "impossible";}
};int main()
{#ifndef ONLINE_JUDGEfreopen("/home/fcbruce/文档/code/t","r",stdin);#endif // ONLINE_JUDGEreturn 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 55using 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_JUDGEfreopen("/home/fcbruce/文档/code/t","r",stdin);#endif // ONLINE_JUDGEInvariantSets 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;
}

转载于:https://www.cnblogs.com/mfrbuaa/p/4265632.html

Topcoder SRM 628 DIV 2相关推荐

  1. Topcoder SRM 648 (div.2)

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

  2. Topcoder SRM 663 DIV 1

    ABBADiv1 题意: 规定两种操作,一种是在字符串的末尾添加A,另一种是在末尾添加B然后反转字符串.现在给你一个起始串,一个终点串,然后问你是否能够通过以上两种操作,从起始串变为终点串. 题解: ...

  3. TopCoder SRM 152 div 2 500point

    这个题目比较简单,自己在纸上写出来给的例子,然后分析一下就会发现规律了:) 我的代码 #include<vector> #include<iostream> using nam ...

  4. topcoder srm 628 div2 250 500

    做了一道题,对了,但是还是掉分了. 第二道题也做了,但是没有交上,不知道对错. 后来交上以后发现少判断了一个条件,改过之后就对了. 第一道题爆搜的,有点麻烦了,其实几行代码就行. 250贴代码: 1 ...

  5. Topcoder SRM 638 DIV 2 (大力出奇迹)

    水题,就是一个暴力.大力出奇迹. Problem Statement   There is a narrow passage. Inside the passage there are some wo ...

  6. Topcoder SRM 637 (Div.2)

    A.GreaterGameDiv2 不能更水 1 #line 7 "GreaterGameDiv2.cpp" 2 #include<cstdio> 3 #include ...

  7. TopCoder SRM 558 Div 1 - Problem 1000 SurroundingGame

    传送门:https://284914869.github.io/AEoj/558.html 题目简述  一个人在一个n * m棋盘上玩游戏,想要占领一个格子有两个方法: 在这个格子放一个棋子.   这 ...

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

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

  9. Topcoder SRM 697题解

    Topcoder SRM 697题解 D1L1 分子分母同乘a[i]: \(a_{i}^{b_{i}+1} mod \prod a_i = 0\) 然后我们考虑质因子p,设质因子p在a[i]中出现cn ...

最新文章

  1. 在Fedora 14上安装Sun JDK 6 (转载)
  2. 送分题,ArrayList 的扩容机制了解吗?
  3. Spring Boot 入门程序
  4. python中循环结构break_Python编程10:跳出循环结构之break和continue
  5. Linux _ Day8 Shell编程之字符截取命令
  6. solidworks中皮带同步轮配合如何做?几张图教会你
  7. 关于区块链的一点经济学思考
  8. 【Elasticsearch源码】 更新性能分析
  9. 计算机本科生也能轻松发表SCI论文?纪念我第一篇论文的心路历程
  10. 返利平台php,MallWWI新模式返利商城系统 php版 v1.2.7
  11. 只有程序员才能看懂的16张高端漫画
  12. html点击按钮跳出消息框
  13. CentOS安装XenServer Tools
  14. 浙大MBA考研经验分享:名校梦不可负~
  15. 汽车4G车载智能终端
  16. 高质量深度学习资源总结:128篇论文,21大领域
  17. 颠覆传统下载体验 QNAP迅雷系列NAS重磅登场
  18. 职场社交软件脉脉职言区最近一个星期在聊什么?
  19. html5 字体位置,html5字体样式 移动 html5 中文什么字体
  20. L1-054 福到了(Python3)

热门文章

  1. 回溯和递归的区别(简述)
  2. python识别人脸多种属性_OpenCV-Python(3)训练一个人脸识别器
  3. intelliJ Idea 添加 Tomcat部署(详细步骤)
  4. 用户访问共享计算机没有权限,win7共享没有权限访问 共享文件访问权限的方法...
  5. intel fpga 开发工具Quartus Prime 软件的安装,使用详细教程
  6. python半年能达到什么程度_花半年的时间能把Python自学到什么程度?
  7. python ui自动化测试框架_基于python语言下的UI自动化测试框架搭建(一)
  8. 关于21年电赛,这些一定要熟悉!
  9. 砰的一声,实验室又炸鸡了
  10. PCB板上的“特殊焊盘”到底起什么作用?