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. win10上VMare安装Centos7并使用Xshell连接Centos

      一.CentOS 使用VMware虚拟机如何上网 1.宿主机的虚拟网关VMnet8的IP设置为自动获取. (1)打开控制面板:“控制面板” ---> “网络和 Internet” ---&g ...

  2. How to install VCM 2 Ford IDS 109 software

    How to install Ford IDS 109: 1- Install the ids 86 before changing the date to 1 07 2015 (hold the d ...

  3. Luogu2149 [SDOI2009]Elaxia的路线-最短路+拓扑排序

    Solution 另外$ m <=5e5$. 两条最短路的 最长公共路径 一定是若干条连续的边, 并且满足拓扑序. 于是我们分别 正向 和反向走第二条路径,若该条边同时是两条最短路径上的边, 则 ...

  4. HTML的报告

    import HTMLTestRunner class HTMLReporter(object): def reporter(self,filename,reportername,reporterdi ...

  5. Python之路(第二十二篇) 面向对象初级:概念、类属性

    一.面向对象概念 1. "面向对象(OOP)"是什么? 简单点说,“面向对象”是一种编程范式,而编程范式是按照不同的编程特点总结出来的编程方式.俗话说,条条大路通罗马,也就说我们使 ...

  6. 原生js的dom操作

    父节点parentNode 第一个子节点 只会获取到元素节点 firstElementChild ★★★★★    ​ 第一个子节点 (如果有文本节点将会获取到文本节点) firstChild ​ 最 ...

  7. Java SE学习【二】——面向对象

    面向对象的学习也进行了一段时间,这段时间学了,类和对象:属性:方法:封装:继承:多态:接口.也算是有一些自己的理解,不愧是贴近人类思维的思想,老师讲时我常常会想到以前的一些事物和其交相印证,其中最常想 ...

  8. Reading CLR via c# 4th Edition

    In fact, at runtime, the CLR has no idea which programming language the developer used for thesource ...

  9. 36、NSTimer使用详解-开启、关闭、移除

    1.要是用一个定时器,首先要定义一个定时器: @property(strong,nonatomic)NSTimer *myTimer;//定时器 2.初始化,初始化有两种方式: 第一种: + (NST ...

  10. Python里的拷贝

    可变数据类型:list.dict 不可变数据类型:int.float.string.tuple 引用 https://github.com/taizilongxu/interview_python#4 ...