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的更多相关文章

  1. SRM470 - SRM474(1-250pt,500pt)(471-500pt为最短路,474-500pt未做)

    SRM 470 DIV1 250pt 题意:有n个房间排成一排,相邻两个房间之间有一扇关闭着的门(共n-1扇),每个门上都标有‘A’-‘P’的大写字母.给定一个数n,表示第n个房间.有两个人John和 ...

随机推荐

  1. nginx 启动报错 “/var/run/nginx/nginx.pid" failed” 解决方法

    问题: 重启虚拟机后,再次重启nginx会报错: open() "/var/run/nginx/nginx.pid" failed (2: No such file or dire ...

  2. Luogu 1641[SCOI2010]生成字符串 - 卡特兰数

    Description 有$N$ 个 $1$ 和 $M$ 个 $0$ 组成的字符串, 满足前 $k$ 个字符中 $1$ 的个数不少于 $0$ 的个数. 求这样字符串的个数. $1<=M < ...

  3. android udp 无法收到数据 (模拟器中)

    解决方法:1. 运行模拟器2. 打开window 命令行执行:telnet localhost 55545554是模拟器的端口,执行之后会进入android console3. 在console下执行 ...

  4. web.xml 详细介绍(zz)

    web.xml 详细介绍 博客分类: CoreJava WebXMLServletJSPTomcat  http://mianhuaman.iteye.com/blog/1105522 1.启动一个W ...

  5. Roslyn研究随笔

    Roslyn概述: http://blogs.ejb.cc/archives/7604/dotnet-compile-platform-roslyn-overview 使用Microsoft Rosl ...

  6. 【NIFI】 Apache NiFI 之 ExecuteScript处理(一)

    本例介绍NiFI ExecuteScript处理器的使用,使用的脚本引擎ECMScript FlowFile I / O简介 NiFi中的流文件由两个主要组件构成,即属性和内容.属性是关于内容/流文件 ...

  7. 【Apache】Apache服务的基本概念(二)

    Apache服务的基本概念 Apache安装请参照:[Apache]Apache服务的安装(一) 1.端口 apache默认监听TCP协议端口80端口 2.apache服务 apache服务默认会启动 ...

  8. hdu6069 多校Counting Divisors

    思路:对于n^k其实就是每个因子的个数乘了一个K.然后现在就变成了求每个数的每个质因子有多少个,但是比赛的时候只想到sqrt(n)的分解方法,总复杂度爆炸,就一直没过去,然后赛后看官方题解感觉好妙啊! ...

  9. python之并发编程进阶篇9

    一.守护进程和守护线程 1)守护进程的概念 什么是守护进程: 守护: 在主进程代码结束情况下,就立即死掉 守护进程本质就是一个子进程,该子进程守护着主进程 为何要用守护进程 守护进程本质就是一个子进程 ...

  10. poj-2406(字符串hash)

    题目链接:传送门 思路:字符串hash,终止条件竟然判断错了,真是太大意了. #include<iostream> #include<cstdio> #include<c ...