SRM482
250pt
题意:给定n把锁,第i轮每间隔i个打开一个木有打开的。问最后打开的事几
思路:直接vector模拟
code:
#line 7 "LockersDivOne.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) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII; class LockersDivOne
{
public:
int get(int n){
vector<int> a, b;
for (int i = ; i < n; ++i)
a.push_back(i);
int res = ;
for (int i = ; ; ++i){
if (a.size() == ) break;
b.clear();
for (int j = ; j < a.size(); j++)
if (j % i == ) res = a[j] + ;
else b.push_back(a[j]);
a = b;
}
return res; }
int lastOpened(int N)
{
return get(N);
}
};
500pt
题意:A和B两个人玩汉诺塔,其中A移动汉诺塔用最快的方法,移动的步数是2^n-1步,而B用的方法可以保证每种状态恰好被访问到一次,移动的步数是3^n-1。两个人移动的伪代码都给定,问第一个人移动K步后的configuration,按照第二个人的方法需要移动多少步。
思路:先算出最终的状态。然后根据最终的状态用递归算出答案。
code:
#line 7 "HanoiGoodAndBad.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) typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long LL;
typedef pair<int,int> PII;
int thr[]; class HanoiGoodAndBad
{
public:
int dd, ans;
int H[][];
int top[];
void solve_Dave(int a, int c, int b, int n){
if(n > ){
if (dd == ) return;
solve_Dave(a, b, c, n-);
if (dd == ) return;
H[c][++top[c]] = n;
H[a][top[a]--] = ;
--dd;
solve_Dave(b, c, a, n-);
}
}
void solve_Earl(int a, int c, int b, int n){
if (n == ) return;
int P = ;
if (H[][top[]] == n) P = ;
if (H[][top[]] == n) P = ;
top[P]--;
if (P == c){
ans += * thr[n-];
solve_Earl(a, c, b, n-);
}
if (P == b){
ans += thr[n-];
solve_Earl(c, a, b, n-);
}
if (P == a) solve_Earl(a, c, b, n-);
}
int moves(int N, int Dave)
{
dd = Dave;
memset(top, , sizeof(top));
memset(H, , sizeof(H));
for (int i = N; i >= ; --i) H[][++top[]] = i;
solve_Dave(, , , N);
ans = ;
for (int i = ; i < ; ++i)
for (int j = ; j <= top[i]/ ; ++j)
swap(H[i][j], H[i][top[i]-j+]);
thr[] = ;
for (int i = ; i <= ; ++i) thr[i] = thr[i-] * ;
solve_Earl(, , , N);
return ans;
}
};
SRM482的更多相关文章
随机推荐
- Porsche PIWIS III with V37.250.020 Piwis 3 Software Update New Feature
Porsche Piwis tester 3 PT3G VCI with V37.250.020 Piwis 3 Software unlimited license installed on Ful ...
- Cannot switch on a value of type String for source level below 1.7. Only convertible int values or enum variables are permitted
在java中写switch代码时,参数用的是string,jdk用的是1.8,但是还是报错,说不支持1.7版本以下的,然后查找了项目中的一些文件,打开一个文件如下,发现是1.6的版本,好奇怪啊,按照e ...
- 代码UITableView点击cell跳转
首先,在tableViewController中设置好 代理和数据源方法: @interface FirstTableViewController ()<UITableViewDataSourc ...
- Windows 下 Phpstrom 配置git使用
首先先去下载 git 下载链接 https://git-scm.com/download/winphpstrom 配置git 链接 http://jingyan.baidu.com/artic ...
- P1083龙舟比赛
题目如下: 现在正在举行龙舟比赛,我们现在获得了最后冲刺时的俯视图像,现在你要输出各条龙舟的名次. 这张图像由r行c列的字符组成,每行的最左边的字符表示起点,所以字符为'S',最右边的字符为'F'.并 ...
- oracle 62进制序列号
create or replace function GetSerial62(v_lpad number default 0) return varchar2 IS v_tmp number(38,0 ...
- ListView动态改变每一项的高度。
ListView中每一项的高度默认是相同的,除非超过其预定高度值,否则需要动点手脚. VariableSizedListView 继承 ListView然后重写protected override v ...
- Java语法基础课 原码 反码 补码
原码就是符号位加上真值的绝对值, 即用第一位表示符号, 其余位表示值. 反码的表示方法是:正数的反码是其本身:负数的反码是在其原码的基础上, 符号位不变,其余各个位取反. 补码的表示方法是在反码的基础 ...
- 2018.12.08 codeforces 946D. Timetable(背包)
传送门 题意简述:有一个人上n天课,每天有m个小时的时间安排表(一个01串),为1表示要上课,否则不上课,求出如果可以最多翘kkk节课这nnn天在校待的总时间的最小值(一天必须在所有课上完后才能离开) ...
- sprintf()与sscanf()
1.sprintf() sprintf()用于向字符串中写入格式化的数据,eg: int dSrc1 = 1; int dSrc2 = 2; char str[] = "hello" ...