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的更多相关文章
随机推荐
- XiaoKL学Python(E)Generator Expressions
在 阅读 https://github.com/vitonzhang/objc_dep 中的 objc_dep.py 时遇到: objc_files = (f for f in files if f. ...
- ZBlog你选择PHP还是ASP?
最近趁着空闲玩了一下zblog,对于很多第一次接触zblog的博主大多都会问zblog是PHP好还是ASP好?我们应该如何选择?其实,对于这个问题我也不是很懂,我个人比较倾向于PHP.今天我就整理一下 ...
- 多字节字符集与Unicode字符集
在计算机中字符通常并不是保存为图像,每个字符都是使用一个编码来表示的,而每个字符究竟使用哪个编码代表,要取决于使用哪个字符集(charset). 多字节字符集: 在最初的时候,Internet上只有一 ...
- Delphi、Lazarus保留字、关键字详解
Delphi.Lazarus保留字.关键字详解 来自橙子,万一的博客以及其他地方 保留字:变量等标识符可以再使用: 关键字:有特定含义,不能再次重新定义: 修饰字:类似保留字的功能,也就是说可以重用 ...
- [转]11种常见sqlmap使用方法详解
sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了.今天把我一直 ...
- office 2007,SQL Server 2008,VS2010安装步骤
office 2007,SQL Server 2008,VS2010的安装顺序是不是office 2007,SQL Server 2008,VS2010呢? 前几天先安装了SQL Server 200 ...
- NETSHARP的JAVA开发环境配置
一:JAVA配置 1. netsharp使用java1.8/1.7版本,本文使用1.8版本 2.jdk下载地址:http://www.oracle.com/technetwork/java/javas ...
- SyntaxError: missing ; before statement
做分页功能,遇到了很坑的事情.前台一直报错:SyntaxError: missing ; before statement 最后发现解决办法是eval("("+s+")& ...
- IPutils
package com.mmall.util; import lombok.extern.slf4j.Slf4j;import org.apache.commons.lang3.StringUtils ...
- Bootstrap之Bootstrap组件
一 文本居中 col-xx-offset-xx:水平居中 center-block:使用于不涉及float标签的水平居中,也不涉及列的居中,让哪里居中就写到哪里,本质是:margin:0 auto. ...