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. String 练习

    package com.hanqi; import java.util.Random; public class Text { public static void main(String[] arg ...

  2. Codeforces55D Beautiful numbers

    原题链接 虽然依旧是套模板,但是因为我太弱了,不会建状态,所以去看了题解.. 这里就直接引用我看的题解吧,写的不错的. 题解 //我的代码 #include<cstdio> #includ ...

  3. MySQL 检索数据及提高检索速度的方法

    检索数据 mysql> SELECT [DISTINCT] 表名.列名,表名.列名,表名.列名 -- 使用通配符*表示所有列 DISTINCT表示返回不同的值 -> FROM 数据库名.表 ...

  4. TI and RI

    https://blog.csdn.net/qq_27977257/article/details/70677661 51单片机的串口,是个全双工的串口,发送数据的同时,还可以接收数据.当串行发送完毕 ...

  5. 论坛:设计实体-->分析功能-->实现功能 之 《分析功能》

    其中 管理文章 的功能没有做,以下做的设计 浏览与参与 功能的步骤 分析功能   5个功能.   7个请求. 实现功能   Action, 7个方法   Service   Dao   Jsp For ...

  6. 我的MVP呢?

    Ladies and gentelmen, welcome the MVP of NBA 16-2017 Season:... 呃,等下,好像哪里不对.那是因为,我要说的MVP根本就不是Most Va ...

  7. 使用Python完成表格自动输入

    看了看<Python编程快速上手>,写了个小脚本完成12306登录数据的自动输入.如下: 1 import webbrowser 2 import pyautogui 3 import t ...

  8. 使用django发送邮件(smtp)

    首先在 seeting 最下面+上 EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'EMAIL_USE_TLS = False ...

  9. List<T>中,Remove和RemoveAt区别

    Remove删除的是匹配的第一项.比如你的list里面有2个相同的项.那么就删除第一个.后面的不删除,找不到元素和删除失败都返回falseRemoveAt是删除索引下的项

  10. Java 208 道面试题:Java 基础模块答案

    目前市面上的面试题存在两大问题:第一,题目太旧好久没有更新了,还都停留在 2010 年之前的状态:第二,近几年 JDK 更新和发布都很快,Java 的用法也变了不少,加上 Java 技术栈也加入了很多 ...