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 JavaScript语法练习
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- ubuntu下firefox打开mht文件
1.安装firefox插件:UnMHT 插件地址:http://www.unmht.org/unmht/en_index.html 2.用firefox打开mht文件
- ui设计教程分享:关于Logo设计要素
1. 视觉上”一语双关 我最喜欢的一些Logo在视觉设计上”一语双关”,将两张图片.两张意象巧妙结合,合二为一. WinePlace 的Logo就是一个绝佳的案例 这个Logo看起来像图钉,暗喻着 ...
- 20165213 java学习第一周
20165213 -2018-2<Java程序设计>第一周学习总结 教材学习内容总结 java的四个特点:面向对象.平台无关性.动态性.简单. java编写程序步骤:再有jdk的情况下,先 ...
- Linux安装及入门
Linux安装及学习 Linux遇到的问题: 在安装过程中因为代码输错(少空格)而质疑自己下载的ubuntu和virtualbox版本,于是卸载之后重新安装了一次,后来才发现是代码输错了(教程中的空格 ...
- QueryRunner类的八种结果处理集
package cn.jy.demo; import java.sql.Connection; import java.sql.SQLException; import java.util.List; ...
- python r r+ w w+ rb 文件打开模式的区别
# 只读模式with open ( "file.txt" ,'r' ) as f: for line in f.readlines(): ...
- python之web开发“三剑客”
# django import django # flask import flask # tornado import tornado
- 博客写作的Checklist
Checklist 1.不要发明术语. 2.不要使用指代不清的代词.如:我,他. 3.不要使用错误的承前省. 4.不要使用口语. 5.给出结论之前,先交代背景. 6.站立会议报告中应有燃尽图. 7.燃 ...
- 企业IT资产管理功能大全