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的更多相关文章

随机推荐

  1. git报“commiter email "root@localhost.localdomain"does not match your user account”

    首先检查账户邮箱配置是否正确,检查方法: git config --list 发现邮箱及帐号配置正确,但是git push时仍然报如题错误: 原因:git执行add.commit 时已经记录下了做了该 ...

  2. Writing modular applications with laravel-modules

    01-07-2016 Let me start by saying Laravel is an amazing framework. However when it comes to writing ...

  3. 如何烧写BIOS到SD卡里面

    针对TINY6410 ADK型号 1.SD卡格式化为FAT32或者FAT格式 2.将SD卡插入USB接口的读卡器,并插在PC的USB口 3.“以管理员身份运行”SD-Flasher.exe(在tiny ...

  4. java通过IP地址获取物理位置

    import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern ...

  5. TensorFlow实现的激活函数可视化

    书上的代码: # coding: utf-8 # In[1]: import matplotlib.pyplot as plt import numpy as np import tensorflow ...

  6. *1LL在c++中的意义

    LL其实代表long long,*1LL是为了在计算时,把int类型的变量转化为long long,然后再赋值给long long类型的变量 ANS=1LL*num*((1LL)*n*(n-1))/2 ...

  7. SpringMVC作用域传值几种方式

    一.SpringMVC 作用域传值的几种方式 1  使用原生Servlet 1.1 在 HandlerMethod 参数中添加作用域对象 1.1.1 ServletContext不能在方法参数中获取, ...

  8. 686. Repeated String Match

    方法一.算是暴力解法吧,拼一段找一下 static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); cl ...

  9. 2018.11.07 bzoj2751: [HAOI2012]容易题(easy)(组合数学)

    传送门 组合数学一眼题. 感觉一直做这种题智商会降低. 利用组合数学的分步计数原理. 只用关心每个数不被限制的取值的总和然后乘起来就可以了. 对于大部分数都不会被限制,总和都是n(n+1)2\frac ...

  10. 2018.11.01 loj#2319. 「NOIP2017」列队(线段树)

    传送门 唉突然回忆起去年去noipnoipnoip提高组试水然后省二滚粗的悲惨经历... 往事不堪回首. 所以说考场上真的有debuffdebuffdebuff啊!!!虽然当时我也不会权值线段树 这道 ...