TC SRM 584 DIV2
250pt:
水题set处理。
500pt:
题意:
给你一个图,每条边关联的两点为朋友,题目要求假设x的金钱为y,则他的左右的朋友当中的钱数z,取值为y - d <= z <= y + d.求使得任意两点的最大金钱差值,若果是inf输出-1.
思路:
求任意两点的最短的的最大值即可,比赛时不知道哪地方写搓了,直接被系统样例给虐了,老师这么悲剧500有思路能写,老师不仔细哎..
floyd求任意两点的最短距离好写一些。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll __int64
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 25000
#define N 207 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ; int f[N][N];
int n;
void floyd()
{
for (int k = ; k <= n; ++k)
{
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j)
{
if (f[i][k] != inf && f[k][j] != inf && f[i][j] > f[i][k] + f[k][j])
{
f[i][j] = f[i][k] + f[k][j];
}
}
}
} }
class Egalitarianism
{
public:
int maxDifference(vector <string> isF, int d)
{
n = isF.size();
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j) f[i][j] = inf;
}
for (int i = ; i < n; ++i)
{
for (int j = ; j < n; ++j)
{
if (isF[i][j] == 'Y')
{
f[i + ][j + ] = ;
}
}
}
floyd();
int Ma = ;
for (int i = ; i <= n; ++i)
{
for (int j = ; j <= n; ++j)
{
if (i == j) continue;
Ma = max(Ma,f[i][j]);
}
}
if (Ma == inf) return -;
else return Ma*d;
}
};
100pt:
题意:
有n个城市,给出每个城市的类型kind[i]表示i城市属于kind[i]类,然后给出已经发现的类型found[i]表示发现了found[i]类型, 然后给出k求满足有k个城市,并且这k个城市包含了m中已将发现的类型。(k个城市都是从已经发现的类型里面选的) 也即:知道m种数的每种数个数,然后将这些数放入K个箱子里面连,每个箱子只能放一个,要求放完后这k个箱子的数的种数为m
思路:
才开始想用组和公式方看看怎么放,可是那样考虑会有很多重复,而且不好去重。
dp其实很简单,可是就是想不到,弱逼的DP啊。 dp[i][j] 表示一共放了j个箱子,并且放了i种 则dp[i][j] += dp[i - 1][j - p]*c[found[i]][p];
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0)
#define ll long long
#define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define keyTree (chd[chd[root][1]][0])
#define Read() freopen("din.txt", "r", stdin)
#define Write() freopen("dout.txt", "w", stdout); #define M 25000
#define N 107 using namespace std; const int inf = 0x7f7f7f7f;
const int mod = ;
ll dp[N][N];
ll c[][];
void init()
{
for (int i = ; i <= ; ++i)
{
c[i][i] = c[i][] = ;
}
for (int i = ; i <= ; ++i)
{
for (int j = ; j < i; ++j)
{
c[i][j] = c[i - ][j] + c[i - ][j - ];
}
}
}
class Excavations2
{
public:
int num[N]; long long count(vector <int> kind, vector <int> found, int K)
{
init();
int n = kind.size();
int m = found.size();
CL(num,); for (int i = ; i < n; ++i) num[kind[i]]++;
CL(dp,); dp[][] = ; for (int i = ; i < m; ++i)
{
for (int j = ; j <= K; ++j)
{
for (int p = ; p <= num[found[i]]; ++p)
{
if (j - p >= )
dp[i + ][j] += dp[i][j - p]*c[num[found[i]]][p];
}
}
}
return dp[m][K];
}
};
TC SRM 584 DIV2的更多相关文章
- TC SRM 584 DIV 2
第一次在DIV2 AK了. 250水题. 500,FLoyd搞出所有边的最短路,然后找最短路,中最长的,如果有不连通的边返回-1 1000,组合DP,各种慌乱,在最后1分钟时,交上了,感觉很棒,最后还 ...
- TC SRM 663 div2 B AABB 逆推
AABB Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description One day, Jamie noticed that many En ...
- TC SRM 663 div2 A ChessFloor 暴力
ChessFloor Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description Samantha is renovating a squa ...
- TC SRM 665 DIV2 A LuckyXor 暴力
LuckyXorTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 TC Description A lucky number is a positive int ...
- TC SRM 593 DIV2 1000
很棒的DP,不过没想出,看题解了..思维很重要. #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 591 DIV2 1000
很不错的一题,非常巧妙的用DP顺序解决这个问题... 可以发现,只和A里面最小的有关系... #include <cstdio> #include <cstring> #inc ...
- tc srm 636 div2 500
100的数据直接暴力就行,想多了... ac的代码: #include <iostream> #include <cstdio> #include <cstring> ...
- TC SRM 664 div2 B BearPlaysDiv2 bfs
BearPlaysDiv2 Problem Statement Limak is a little bear who loves to play. Today he is playing by ...
- TC SRM 664 div2 A BearCheats 暴力
BearCheats Problem Statement Limak is an old brown bear. Because of his bad eyesight he sometime ...
随机推荐
- windowSoftInputMode
有个问题困扰我一晚上,每次进入Activity后,EditText自动获得焦点弹出软键盘,键盘遮挡listView,使得无法显示最后一条消息.我在edittext点击事件中也设定了,listView. ...
- Android开发规范——命名
在讲解命名规范前,先初略介绍下当前主要的标识符命名法和英文缩写规则.标识符命名法标识符命名法最要有四种: 1 驼峰(Camel)命名法:又称小驼峰命名法,除首单词外,其余所有单词的第一个字母大写. ...
- log4net类库配置、WebService配置
一.类库配置 结构如下图 1.LogUtility类 public class LogUtility { private static readonly log4net.ILog log = log4 ...
- 百度地图api添加自定义控件
官网栗子:http://lbsyun.baidu.com/jsdemo.htm#b0_6 <!DOCTYPE html><html><head> <meta ...
- 使用Yii2中dropdownlist实现地区三级联动的例子
原文:http://www.yiichina.com/code/636 <?php use yii\helpers\Url; use yii\widgets\ActiveForm; use yi ...
- 知乎live 我的读书经验 总结
https://www.zhihu.com/lives/757587093366009856/messages 碎片化阅读没有意义, 捡硬币捡成富翁 kindle不能全文检索 短篇文章的阅读是否有 ...
- HDU Today---hdu2112(最短路-_-坑在是无向图)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2112 spfa或者迪杰斯特拉都可以 注意公交车是有来回的--- #include <iostre ...
- Wormholes---poj3259(最短路 spfa 判断负环 模板)
题目链接:http://poj.org/problem?id=3259 题意是问是否能通过虫洞回到过去: 虫洞是一条单向路,不但会把你传送到目的地,而且时间会倒退Ts. 我们把虫洞看成是一条负权路,问 ...
- 002-and design-基于dva的基本项目搭建
一.概述 在真实项目开发中,你可能会需要 Redux 或者 MobX 这样的数据应用框架,Ant Design React 作为一个 UI 库,可以和任何 React 生态圈内的应用框架搭配使用.我们 ...
- python之__setattr__常见问题
#__setattr__ class Foo(object): def set(self,k,v): pass def __setattr__(self, key, value): print(key ...