SRM483
250pt
题意:给定一个[0,1)间的实数,一个分母不超过maxDen的分数逼近。。
思路:直接枚举。然后判断。
code:
#line 7 "BestApproximationDiv1.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 eps 1e-9
#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; class BestApproximationDiv1
{
public:
string findFraction(int maxDen, string number)
{
int A = , B = , C = ;
for (int i = ; i <= maxDen; ++i)
for (int j = ; j < i; ++j){
double tmp = (j + .) / (i + .) + eps;
int cnt = ;
// if (i == 7 && j == 1){
// cout << "fuck" << endl;
// }
for (int k = ; k < ; ++k){
tmp *= ;
int x = floor(tmp);
tmp -= x;
if (x == number[k+]-) ++cnt;
else break;
}
if (cnt > C || (cnt == C && i < B)){
C = cnt;
A = j;
B = i;
}
}
string res(""), s;
stringstream ss;
ss << A;
ss >> s;
res += s + "/";
ss.clear();
ss << B;
ss >> s;
res += s;
res += " has ";
ss.clear();
ss << C;
ss >> s;
res += s;
res += " exact digits";
return res;
}
};
500pt
题意:n<=50 个人排成1排,每个人都有一个抵抗值和影响力(均小于500),如果收买第i个人,那么跟他距离为k抵抗值的值减少influence[i] / 2^k。
求最少收买都少人,使得每个人的抵抗值降为0.
思路:刚开始确实往最大流甚至费用流想了。不过想了好久还是没想到怎么做。。
后来看了题解才知道是dp。并且突破口是每个人最多影响他旁边的8个人(当然,也就最多左右8个人影响到他)
所以,我们可以预处理出一个数组can[i][1 << 17]表示以i为中心的17个人的状态一直的情况下,第i个人是否抵抗值降为小于等于0
那么我们设dp[i][mask]表示第i个人为中心的17个人的状态为mask情况下最少安排多少人
那么我们就可以用dp[i][mask]转移到dp[i+1][mask>>1] 和dp[i+1][mask>>1|(1 << 16)](前提是can[i+1][mask>>1]和dp[i+1][mask>>1|(1 << 16)]为true)
code:
// BEGIN CUT HERE
/* */
// END CUT HERE
#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;
} };
SRM483的更多相关文章
随机推荐
- Pandas基本介绍
1.pandas主要的两个数据结构:Series和DataFrame Series的字符串表现形式为:索引在左边,值在右边.由于我们没有为数据指定索引.于是会自动创建一个0到N-1(N为长度)的整数型 ...
- Android.DebugTools.Traceview & dmtracedump
1. Android 调试工具之Traceview http://www.cnblogs.com/devinzhang/archive/2011/12/18/2291592.html TraceVie ...
- redis的五种存储类型的具体用法
String 类型操作 string是redis最基本的类型,而且string类型是二进制安全的.意思是redis的string可以包含任何数据.比如jpg图片或者序列化的对象 $redis-> ...
- RavenDb使用
在Raven中查询数据,查询条件必须在index中. 如果查询条件不在index中就会出现如下异常 var query = session.DynamicIndexQuery<ServicePr ...
- 检查mysql是否运行
netstat -tunple|grep mysql
- [SoapUI] 在SoapUI中通过Groovy脚本执行window命令杀掉进程
//杀Excel进程 String line def p = "taskkill /F /IM EXCEL.exe".execute() def bri = new Buffere ...
- [RF]怎样用Robot Framework写好Test Case?
1.介绍 这是一个关于如何用Robot Framework写好Test Case的高层次的指导准则 怎样实际的与系统进行交互不在此文档范围内 最重要的准则是使测试用例尽可能的让熟悉此领域的人觉得简单易 ...
- C# 遇到 which has a higher version than referenced assembly
当C#遇到这种提示: which has a higher version than referenced assembly, 说明有两个或多个工程引用的dll的版本有出现不一样, 如: A工程引用l ...
- javascript声明对象时 带var和不带var的区别
2015/11/25补充: 关于变量声明这里有详细的解释: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Stat ...
- 别人的Linux私房菜(2)Linux简介
同一操作系统无法在不同硬件平台上运行.架构. Bell实验室和麻省理工学院MIT和通用电气公司GE发起了Multics计划,分时兼容系统,300以上多终端连接主机. Unics 由Multics中的人 ...