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

随机推荐

  1. phpstorm的安装和使用

    1下载phpstorm #下载地址 https://www.jetbrains.com/phpstorm/ 2激活并安装 create associations 表示的是以后编辑选择的文件也默认用id ...

  2. nodejs 如何操作字节在内存中的位置问题 BE LE

    上代码 function testNumber() { var arr = new Int32Array(1); arr[0] = 1234; var buf1 = Buffer.from(arr); ...

  3. urllib和requests库

    目录 1. Python3 使用urllib库请求网络 1.1 基于urllib库的GET请求 1.2 使用User-Agent伪装后请求网站 1.3 基于urllib库的POST请求,并用Cooki ...

  4. Notepad++ tab替换为4个空格

  5. NOIP水题测试(2017082501)

    日常水题测试又来了! 以后答案都以单题形式公布. 下面看今天的水题: 时间限制:5小时 题目一:无法形容的水 题目二:比上一题还水 题目三:一元三次方程求解 题目四:单词接龙 题目五:统计单词个数 题 ...

  6. FMS是什么?

  7. 2019.02.09 codeforces gym 100548F. Color(容斥原理)

    传送门 题意简述:对n个排成一排的物品涂色,有m种颜色可选. 要求相邻的物品颜色不相同,且总共恰好有K种颜色,问所有可行的方案数.(n,m≤1e9,k≤1e6n,m\le1e9,k\le1e6n,m≤ ...

  8. Educational Codeforces Round 53 (Rated for Div. 2) E. Segment Sum

    https://codeforces.com/contest/1073/problem/E 题意 求出l到r之间的符合要求的数之和,结果取模998244353 要求:组成数的数位所用的数字种类不超过k ...

  9. linux利用命令将一个盘上的所有复制到另一个盘上

    1.fdisk -l 查看硬盘状况 2.将目标盘利用mount挂载 3.查看硬盘使用状况,看目标盘是否有足够的空间:df -h 4.如果足够,利用dd命令将源盘数据拷贝到目标盘:dd if=/dev/ ...

  10. c# 快速排序法并记录数组索引

    在遗传算法中,只需要对适应性函数评分进行排序,没必要对所有的个体也参与排序,因为在适应性函数评分排序是可以纪律下最初的索引,排序后的索引随着元素排序而变动,这样就知道那个评分对应那个个体了: usin ...