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}$个第 ...
随机推荐
- *jquery操作DOM总结 (原创:最全、最系统、实例展示)
jquery操作DOM包括八个方面: 一:jquery对DOM节点的基本操作:二:jquery对DOM节点的CSS样式操作:三:jquery遍历DOM节点:四:jquery创建DOM节点:五:jque ...
- js的日期格式判断
var reg = /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/; var str = (new Date).toLocaleString() ...
- 常用MFC宏
最近我在用MFC开发一个智能家居监控平台的软件(用到了MSCOMM串口通信控件),当我通过在一个对话框类A中定义另一个对话框类B的对象访问B的public成员时,提示不可访问.后来经过多天的向朋友求救 ...
- 使用Loadrunner对IBM MQ进行性能测试
一.概述 使用Loadrunner对IBM MQ进行性能测试,需要用到java vuser以及java编码知识.此次先介绍什么是IBM MQ,然后java vuser的使用与配置细节, ...
- Laravel 利用 observer 类基于状态属性,对进行删除和修改的控制
1 我们知道 Observer 类可以监听模型类的相关事件 1.1 creating, created, updating, updated, saving, saved, deleting, del ...
- mysql8.0.4以后修改密码方式变更
https://blog.csdn.net/qq_38265784/article/details/80915098 use mysql: ALTER USER 'root'@'localhost' ...
- Java SE学习【三】——JDBC
最近学到了数据库与java的jdbc方面,还有个DAO模式,写一下自己的理解,后期有什么不对的再改. 一.数据库三范式的理解 记得以前上课时,也上了一学期的“数据库系统原理”,给我们上课的老师算是渣渣 ...
- POI导出大量数据的简单解决方案
说明:我的电脑 2.0CPU 2G内存 能够十秒钟导出 20W 条数据 ,12.8M的excel内容压缩后2.68M 我们知道在POI导出Excel时,数据量大了,很容易导致内存溢出.由于Excel ...
- 【搜索】Fliptile
#include<stdio.h> #include<stdlib.h> #include<string.h> ; ; typedef long long ll; ...
- IPython:一种交互式计算和开发环境(魔术命令,快捷键)
%run命令 在IPython会话环境中,所有文件都可以通过%run命令当做Python程序来运行. 假设在ipython_script_test.py中存放了一段简单的脚本,如下所示: def f( ...