SRM478
又是rng_58的神题。。
250pt:
题意:给定一个初始数x,对于这个数可以进行x*4+3,或者x*8+7的操作。最多进行100000次操作
问最少经过几次出现%1000000007 == 0的情况。。
思路:
x*4+3 = (x * 2 + 1) * 2 + 1
x * 8 + 7 = (x * 4 + 3) * 2 + 1
所以我们发现两个操作都可以合并成x * 2 + 1的操作。所以直接模拟30w次*2+1操作。
如果操作y次*2+1那么答案便是(y + 2) / 3,注意y == 1时无解需特判
code:
#line 7 "CarrotJumping.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 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 CarrotJumping
{
public:
int theJump(int x)
{
for (int i = ; i <= ; ++i){
x = (x * + ) % M;
if (x == && i >= ) return (i + ) / ;
}
return -;
}
};
500pt
题意:有N<=15个杯子,所有杯子的容量都是一样的,为C<50。现在已知每个杯子当前的水量,数量为x的杯子可以卖p[i]的钱。不过在卖之前可以做任意次操作:选两个杯子a和b,把a的水往b倒,知道a空了或者b满了为止。问这些杯子经过操作后,最多一共能卖多少钱。
思路: 如果选中若干个杯子,那么这些杯子的状态便是固定的,因为必须倒到满或者空。
那么集合dp的感觉就很明显了
dp[mask]表示选中mask状态个的被子最多卖多少钱。然后枚举子状态即可。。
code:
#line 7 "KiwiJuice.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 two(i) (1 << i)
#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;
int dp[ << ], cost[ << ];
class KiwiJuice
{
public:
int c, n;
vector<int> b, p;
void calculateCost(int mask){
int v = , bn = ;
for (int i = ; i < n; ++i)
if (two(i) & mask){
v += b[i];
++bn;
}
cost[mask] = p[v % c] + (v / c) * p[c] + p[] * (bn - v / c - );
}
int dfs(int mask){
if (dp[mask] != -) return dp[mask];
dp[mask] = ;
for (int i = mask; i; i = (i-) & mask)
dp[mask] = max(cost[i] + dfs(mask ^ i), dp[mask]);
return dp[mask];
}
int theProfit(int C, vector <int> bottles, vector <int> prices)
{
b = bottles, p = prices;
n = b.size(), c = C;
for (int i = ; i < two(n); ++i)
calculateCost(i);
memset(dp, -, sizeof(dp));
return dfs(two(n) - );
}
};
SRM478的更多相关文章
- [SRM478]RandomApple
题意:有$k$种苹果和$n$个箱子,每个箱子中有一些苹果,先等概率选取$n$个箱子组成集合的非空子集,再从选出的苹果中随机选一个,问每种苹果被选中的概率是多少 设箱子$i$有$cnt_{i,j}$个第 ...
随机推荐
- html 转化成 pdf
- Json数据处理协议与办法
[JSON学习] 一.概述 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文 本格式,是理想的数据交换格式.同时,J ...
- GCC编译的几个步骤
参考资料: https://blog.csdn.net/czg13548930186/article/details/78331692 一个C/C++文件要经过预处理(preprocessing).编 ...
- mysql错误日志
cat /etc/my.cnf
- PhpStorm 为 Laravel 搭建 PhpUnit 单元测试环境
1.PhpStorm 中打开项目的路径为 Laravel 安装的根目录 2.点击右下角 EventLog 提示按钮, 初始化 Composer 的设置 3.打开单元单测试示例类,按提示点击 Fix . ...
- 利用js代码:document.forms[0].approval.value='false',当点击 <input type="image"按钮向表单传递不同的参数。
<form action="flow_myTaskList"> <input type="hidden" name="approva ...
- go语言字符串练习
package main import "fmt" import s"strings" var p = fmt.Println func main() { p( ...
- vc项目中加载多个lib遇到的问题
一个VC项目中 在网络加密 json解析等方面 加载了多个第三方库和文件 boost cryptpp rapidjson mysql的连接池等等 在使用mysql++的时候 多次报错 LNK 20 ...
- Linux入门练习操作命令
查看目录命令 1. 显示目录下所有文件 2.显示所有文件,包括隐藏文件 创建目录命令 1.在改目录下创建文件夹“practise” 切换目录 1.切换到指定的目录 2.切换到上一级目录 3.还在当前目 ...
- .NET发送邮件的方法
整理一下,在.NET中发送邮件的一个方法,代码如下: public static string Net_Email(string strSendto, string strCC, string str ...