Benelux Algorithm Programming Contest 2014 Final
// Button Bashing (bfs)
1 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int T;
int a[];
//int d[8000];//数组的下标可以为负的
//d[i]表示 尽量凑成i需要的最小时间数目
map<int,int>mp;//用map更好
struct Node{
int step,time;
}sta,ed,cnt,tp;
int main()
{
scanf("%d",&T);
while(T--)
{ int n,t;
scanf("%d%d",&n,&t);
for(int i=;i<n;i++)
scanf("%d",&a[i]);
//memset(d,inf,sizeof(d));
for(int i=;i<=;i++)//因为小于0为0,大于3600为3600
{
mp[i]=inf;
}
mp[]=;
// d[0]=0;
sta.step=,sta.time=;
ed.time=inf;//要求的
queue<Node>q;
while(!q.empty()){
q.pop();//清空队列
}
q.push(sta);
while(!q.empty()){
tp=q.front();
q.pop();
if(tp.time>=t){ //满足时间的
if(ed.time>tp.time) ed=tp;//先比时间,要尽量接近t
else if(ed.time==tp.time&&ed.step>tp.step)
ed=tp;
//时间考虑完后,要step尽量少
}
for(int i=;i<n;i++){
int nex=tp.time+a[i];
if(nex<) nex=;
if(nex>) nex=;
// if(d[nex]>=inf){//最先到达nex的时间单元数目一定最少
if(mp[nex]>=inf){
//d[nex]=d[tp.time]+1;
mp[nex]=mp[tp.time]+;
// cnt.step=d[nex];
cnt.step=mp[nex];
cnt.time=nex;
q.push(cnt);
}
}
}
printf("%d %d\n",ed.step,ed.time-t);
} return ;
}
//Interesting Integers
2 /*对于一个n,它在新的数列里最多是第45项,因此可以遍历查找
3 a
4 b
5 a+b
6 a+2*b
7 2*a+3*b
8 3*a+5*b
9 有上面的规律可知 G[i]=f[i-2]*a+f[i-1]*b
10 我们要求的就是 a,b。
11 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int t;
ll f[];
void init()
{
f[]=,f[]=;
for(int i=;i<=;i++)
{
f[i]=f[i-]+f[i-];
}
}
ll egcd(ll a,ll b,ll &x,ll &y)
{
ll d=a;
if(b==){
x=;
y=;
}
else{
d=egcd(b,a%b,y,x);
y-=(a/b)*x;
}
return d;
}
//egcd求出的是a,b的最大公约数
int main()
{
scanf("%d",&t);
init();
while(t--)
{ ll n;
scanf("%lld",&n);
ll l=,r=n;
for(int i=;i<=;i++)//45就已经大于10^9了
{
if(f[i]>n) break;
//G[i]=f[i-2]*a+f[i-1]*b,G[i]最小为f[i]
//G[i]等于n吗
ll x,y;
ll tmp=egcd(f[i-],f[i-],x,y);
if(n%tmp!=) continue;
x*=n,y*=n;////a*x+b*y=1(egcd),是1
ll ans=(y-x)/f[i];
x+=ans*f[i-];
y-=ans*f[i-];
//数学公式可推出:x,y都为(x*f[i-2]+y*f[i-1])/f[i]
if(x>y) {
x-=f[i-];//多加了,减回去
y+=f[i-];
}
//上面的操作是为了让a,b,更接近 if(x<=||y<=) continue;
if(r>y) {//r要小
r=y;
l=x;
}
else if(r==y&&l>x){//r一样大时。l要小
l=x;
}
}
printf("%lld %lld\n",l,r);
}
return ;
}
// Jury Jeopardy
//一道简单的模拟
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int inf=0x3f3f3f3f;
int t;
const int N=1e5+;
char s[N];
bool vis[][];//要大点
void change(int &x,int &y,int &d,char c){//x,y,d要用引用
//不能写成if If if
//例如 d==1,在第一个if中变成了2
//会在下个if 里继续操作
if(d==){
if(c=='R'){
d=;
x=x,y=y+;
}
else if(c=='F'){
d=;
x=x+,y=y;
}
else if(c=='L'){
d=;
x=x,y=y-;
}
else{
d=;
x=x-,y=y;
}
}
else if(d==){
if(c=='R'){
d=;
x=x,y=y-;
}
else if(c=='F'){
d=;
x=x-,y=y;
}
else if(c=='L'){
d=;
x=x,y=y+;
}
else{
d=;
x=x+,y=y;
}
}
else if(d==){
if(c=='R'){
d=;
x=x+,y=y;
}
else if(c=='F'){
d=;
x=x,y=y-;
}
else if(c=='L'){
d=;
x=x-,y=y;
}
else{
d=;
x=x,y=y+;
}
}
else{
if(c=='R'){
d=;
x=x-,y=y;
}
else if(c=='F'){
d=;
x=x,y=y+;
}
else if(c=='L'){
d=;
x=x+,y=y;
}
else{
d=;
x=x,y=y-;
}
}
}
int main()
{
scanf("%d",&t);
int dir,x,y;
printf("%d\n",t);
while(t--){
scanf("%s",&s);
dir=,x=,y=;
int ymin=;
int xmax=,ymax=;
memset(vis,,sizeof(vis));
vis[x][y]=;
for(int i=;i<strlen(s);i++){
change(x,y,dir,s[i]);
vis[x][y]=;
ymin=min(ymin,y);
xmax=max(xmax,x);
ymax=max(ymax,y);
}
ymin-=;//适当变化,四周都是墙壁
ymax+=;
xmax+=;
printf("%d %d\n",ymax-ymin+,xmax-+);//250一定最左
for(int i=ymin;i<=ymax;i++){//一行一行的输出
for(int j=;j<=xmax;j++){
if(vis[j][i]==){//y对应i,往下变大,同理x往右变大。
printf(".");
}
else{
printf("#");
}
}
printf("\n");
}
}
return ;
}
Benelux Algorithm Programming Contest 2014 Final的更多相关文章
- Benelux Algorithm Programming Contest 2014 Final(第二场)
B:Button Bashing You recently acquired a new microwave, and noticed that it provides a large number ...
- 计蒜客 28319.Interesting Integers-类似斐波那契数列-递推思维题 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 I)
I. Interesting Integers 传送门 应该是叫思维题吧,反正敲一下脑壳才知道自己哪里写错了.要敢于暴力. 这个题的题意就是给你一个数,让你逆推出递推的最开始的两个数(假设一开始的两个 ...
- 计蒜客 28317.Growling Gears-一元二次方程的顶点公式 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 G)
G. Growling Gears 传送门 此题为签到题,直接中学的数学知识点,一元二次方程的顶点公式(-b/2*a,(4*a*c-b*b)/4*a):直接就可以得到结果. 代码: #include& ...
- 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)
先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...
- 2014 Benelux Algorithm Programming Contest (BAPC 14)E
题目链接:https://vjudge.net/contest/187496#problem/E E Excellent Engineers You are working for an agency ...
- 2020.3.14--训练联盟周赛 Preliminaries for Benelux Algorithm Programming Contest 2019
1.A题 题意:给定第一行的值表示m列的最大值,第m行的值表示n行的最大值,问是否会行列冲突 思路:挺简单的,不过我在一开始理解题意上用了些时间,按我的理解是输入两组数组,找出每组最大数,若相等则输出 ...
- 2018 Benelux Algorithm Programming Contest (BAPC 18)
目录 Contest Info Solutions A A Prize No One Can Win B Birthday Boy C Cardboard Container D Driver Dis ...
- ICPC训练周赛 Benelux Algorithm Programming Contest 2019
D. Wildest Dreams 这道题的意思是Ayna和Arup两人会同时在车上一段时间,在Ayna在的时候,必须单曲循环Ayna喜欢的歌,偶数段Ayna下车,若此时已经放了她喜欢的那首歌,就要将 ...
- Benelux Algorithm Programming Contest 2019
J. Jazz it Up!题目要求,n*m的因子中不能含有平方形式,且题目中已经说明n是一个无平方因子的数, 那么只要m是无平方因子的数,并且n和m没有共同的因子即可.要注意时间复杂度!代码:#in ...
随机推荐
- JAVA中数组介绍
一.数组: 数组指一组数据的集合,数组中的每个数据被称作元素. 二.数组定义: 数组类型[] 数组名 = new 数组类型[元素个数或数组长度]: (注意:等号前面的[]里面不能写任何东西) 也可以以 ...
- springboot 学习笔记(九)
springboot整合activemq,实现broker集群部署(cluster) 1.为实现jms高并发操作,需要对activemq进行集群部署,broker cluster就是activemq自 ...
- Browser History
History 对象中包含用户(在浏览器窗口中)访问过的URL History 对象是window对象的一部分,可通过window.history属性对其进行访问. 注释:没有应用于History对象 ...
- 零基础逆向工程24_C++_01_类_this指针_继承本质_多层继承
1 类内的成员函数和普通函数的对比 1.1 主要是从参数传递.压栈顺序.堆栈平衡来总结. 1.参数传递:成员函数多传一个this指针 2.压栈顺序:成员函数会将this指针压栈,在函数调用取出 3.堆 ...
- Retrofit 2.0 轻松实现多文件/图片上传/Json字符串/表单
如果嫌麻烦直接可以用我封装好的库:Novate: https://github.com/Tamicer/Novate 通过对Retrofit2.0的前两篇的基础入门和案例实践,掌握了怎么样使用Retr ...
- Mono for Android 设计器错误:Disconnected from layout renderer
今早打开vs2012 android 项目的时候出现如下错误提示: 查了半天,终于在官方网站得到答案.(http://forums.xamarin.com/discussion/143 ...
- linux下配置Nginx,支持thinkphp
前言引入 一个刚入行的朋友,刚换工作,入职了一个新公司.新公司一个php开发,就是他.俨然老板把他当成公司扛把子了,把服务器都给了他,让他部署整个php的开发环境.那个朋友是wamp爱好者.然后面对l ...
- linux 命令——38 cal (转)
cal命令可以用来显示公历(阳历)日历.公历是现在国际通用的历法,又称格列历,通称阳历.“阳历”又名“太阳历”,系以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”. 1.命令格式: cal ...
- TFS看板的迭代规划
故事点 故事点更多体现的是用户情景或者bug的规模,采用斐波拉契数列(1,2,3,5,8,13)这样的数字表示,包含如下内容: 相对工作量 复杂度 风险和不确定性 相对工作量 下面演示一个Case来说 ...
- 异常:System.InvalidOperationException: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms 这个实现是不是Windows平台FIPS验证的加密算法。解决方法
遇见这个问题是在使用了MD5加密算法后报错的,可能的原因如下: 1.FIPS不兼容MD5,此时需要修改注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\C ...