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的更多相关文章
随机推荐
- [中英对照]Introduction to DPDK: Architecture and Principles | DPDK概论: 体系结构与实现原理
[中英对照]Introduction to DPDK: Architecture and Principles | DPDK概论: 体系结构与实现原理 Introduction to DPDK: ...
- qt 5.2.1类和模块的关系图
QT│ ├─ActiveQt│ │ ActiveQt│ │ ActiveQtDepends│ │ ActiveQtVersion│ │ QAxAggregated│ │ QAxB ...
- JSP指令(page include taglib)
JSP指令指示JSP转换器如何翻译JSP页面到Servlet:JSP指令用来设置整个JSP页面相关的属性,如网页编码方式.脚本语言等 JSP指令的格式: <%@ directive attrib ...
- jrebel
jrebel 编辑 JRebel是一套JavaEE开发工具.JRebel允许开发团队在有限的时间内完成更多的任务修正更多的问题,发布更高质量的软件产品. JRebel是收费软件,用户可以在JReb ...
- 使用Narrator读取RichTextBlock内容
先测试基本的RichTextBlock,看能否读取. 测试RichTextBlock中哪些子控件是可以被读取的. 结论:只有Hyperlink能Tab到,能被读取. 问题:RichTextBlock在 ...
- 【Java】使用IDE开发工具远程调试Java代码
概述 服务端程序运行在一台远程服务器上,我们可以在本地服务端的代码(前提是本地的代码必须和远程服务器运行的代码一致)中设置断点,每当有请求到远程服务器时时能够在本地知道远程服务端的此时的内部状态 测试 ...
- Java利用递归实现扫雷
package 扫雷; import java.math.*; import java.util.Scanner; public class 扫雷 { //记录翻开次数 static int k=0; ...
- 459. Repeated Substring Pattern
https://leetcode.com/problems/repeated-substring-pattern/#/description Given a non-empty string chec ...
- mybatis 接口绑定 和 动态SQL
一.MyBatis 接口绑定方案及多参数传递 1.作用:实现创建一个接口后把mapper.xml由mybatis生成接口的实现类,通过调用接口对象就可以获取mapper.xml中编写的sql 2.后面 ...
- java.lang.NoClassDefFoundError: org/apache/solr/common/params/SolrParams
启动tomcat服务,报错误java.lang.NoClassDefFoundError: org/apache/solr/common/params/SolrParams [2016-03-10 2 ...