SRM474
250pt
题意:在一个N维的空间里,有一个人开始在原点,现在给出N<=50个指令序列,每个指令序列为某一维+1或者减一,问是否经过某个点至少2次。
思路:操作很小,直接模拟判断即可
code:
#line 7 "RouteIntersection.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std; #define PB push_back
#define MP make_pair #define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; bool cmp(const pair<int, int>& a, const pair<int,int>& b){
return abs(a.second) > abs(b.second);
} class RouteIntersection
{
public:
vector< PII > P[];
bool equal(int a,int b){
if (P[a].size() != P[b].size()) return false;
for (int i = ; i < P[a].size(); ++i)
if (P[a] != P[b]) return false;
return true;
}
string isValid(int N, vector <int> coords, string moves)
{
int m = coords.size();
P[].clear();
for (int i = ; i <= m; ++i){
int p = -, x = coords[i-], y;
if (moves[i-] == '+') y = ;
else y = -;
P[i] = P[i-];
for (int j = ; j < P[i].size(); ++j)
if (P[i][j].first == x) p = j;
if (p == -) P[i].push_back(make_pair(x, y));
else P[i][p].second += y;
}
for (int i = ; i <= m; ++i){
sort(P[i].begin(), P[i].end(), cmp);
int sz = P[i].size();
while (sz > )
if (P[i][--sz].second == ) P[i].pop_back();
else break;
sort(P[i].begin(), P[i].end());
}
for (int i = ; i <= m; ++i){
// printf("%d\n", P[i].size());
// for (int j = 0; j < P[i].size(); ++j)
// printf("a = %d b = %d ", P[i][j].first, P[i][j].second);
// puts("");
if (!P[i].size()) return "NOT VALID";
for (int j = i+; j <= m; ++j)
if (equal(i, j)) return "NOT VALID";
}
return "VALID";
}
};
500pt
题意:题目给定N<=50的无向连通图,现要你生成一个生成树,并且满足每个点到0的距离正好为原图0到该点的最短路距离。求方案数。
思路:先求一边由0点出发的spfa,并统计每个点的最短路前驱有几个,接着乘法原理即可。
code:
#line 7 "TreesCount.cpp"
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;
#define PB push_back
#define MP make_pair
#define Inf 0x3fffffff
#define REP(i,n) for(i=0;i<(n);++i)
#define FOR(i,l,h) for(i=(l);i<=(h);++i)
#define FORD(i,h,l) for(i=(h);i>=(l);--i)
#define M 1000000007
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class TreesCount
{
public:
int d[], dg[];
bool v[];
int count(vector <string> S)
{
int n = S.size();
memset(dg, , sizeof(dg));
memset(v, , sizeof(v));
for (int i = ; i < n; ++i) d[i] = Inf;
queue<int> q;
q.push();
d[] = ;
dg[] = ;
v[] = true;
int x, dst;
while (!q.empty()){
x = q.front();
for (int y = ; y < n; ++y){
dst = S[x][y] - '';
if (dst > && d[x] + dst <= d[y]){
if (d[x] + dst < d[y]){
dg[y] = ;
d[y] = d[x] + dst;
if (!v[y]) q.push(y), v[y] = true;
}
else ++dg[y];
}
}
v[x] = false;
q.pop();
}
long long ans = ;
for (int i = ; i < n; ++i)
ans = (ans * dg[i]) % M;
return ans;
}
};
SRM474的更多相关文章
- SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)
SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...
随机推荐
- RavenDb使用
在Raven中查询数据,查询条件必须在index中. 如果查询条件不在index中就会出现如下异常 var query = session.DynamicIndexQuery<ServicePr ...
- HDU 6126.Give out candies 最小割
Give out candies Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Other ...
- MySQL学习笔记-数据库后台线程
数据库后台线程 默认情况下讲述的InnoDB存储引擎,以后不再重复声明.后台线程有7个--4个IO thread,1个master thread,1个锁监控线程,1个错误监控线程.IO thread的 ...
- python 正则表达式 group() groups()
参考地址: http://www.cnblogs.com/kaituorensheng/archive/2012/08/20/2648209.html
- jmeter使用HTTP代理服务器
浏览器>web服务器 浏览器>HTTP代理服务器>web服务器 jmeter>HTTP代理服务器>web服务器 浏览器>jmeter HTTP服务器>web服 ...
- Vue单页面应用
单页面应用指一个系统只加载一次资源,然后下面的操作交互.数据交互是通过router.ajax来进 行,页面并没有刷新:<1>在vue搭建的环境里面怎么有没有公用的css和js? ...
- idea15 生成mybatis代码
pom.xml <build> <finalName>mybatis_generator</finalName> <plugins> <plugi ...
- 1.preparation
1)Evarobot 安装 http://wiki.ros.org/Robots/evarobot/Tutorials/indigo/Evarobot%20Installation 2)PC 安装 a ...
- [ASP.NET]static变量和viewstate的使用方法
在.Net平台下进行CS软件开发时,我们经常遇到以后还要用到某些变量上次修改后的值,为了简单起见,很多人都习惯用static来定义这些变量,我也是.这样非常方便,下一次调用某个函数时该变量仍然保存的是 ...
- linux代码笔记
sudo passwd root更新root密码 软件包管理及shell命令_deb软件包管理一_笔记:dpkj -i 安装dpkj -r 移除dpkj -P 全部移除dpkj -L 列出安装清单dj ...