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

  1. Benelux Algorithm Programming Contest 2014 Final(第二场)

    B:Button Bashing You recently acquired a new microwave, and noticed that it provides a large number ...

  2. 计蒜客 28319.Interesting Integers-类似斐波那契数列-递推思维题 (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 I)

    I. Interesting Integers 传送门 应该是叫思维题吧,反正敲一下脑壳才知道自己哪里写错了.要敢于暴力. 这个题的题意就是给你一个数,让你逆推出递推的最开始的两个数(假设一开始的两个 ...

  3. 计蒜客 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& ...

  4. 计蒜客 28315.Excellent Engineers-线段树(单点更新、区间最值) (Benelux Algorithm Programming Contest 2014 Final ACM-ICPC Asia Training League 暑假第一阶段第二场 E)

    先写这几道题,比赛的时候有事就只签了个到. 题目传送门 E. Excellent Engineers 传送门 这个题的意思就是如果一个人的r1,r2,r3中的某一个比已存在的人中的小,就把这个人添加到 ...

  5. 2014 Benelux Algorithm Programming Contest (BAPC 14)E

    题目链接:https://vjudge.net/contest/187496#problem/E E Excellent Engineers You are working for an agency ...

  6. 2020.3.14--训练联盟周赛 Preliminaries for Benelux Algorithm Programming Contest 2019

    1.A题 题意:给定第一行的值表示m列的最大值,第m行的值表示n行的最大值,问是否会行列冲突 思路:挺简单的,不过我在一开始理解题意上用了些时间,按我的理解是输入两组数组,找出每组最大数,若相等则输出 ...

  7. 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 ...

  8. ICPC训练周赛 Benelux Algorithm Programming Contest 2019

    D. Wildest Dreams 这道题的意思是Ayna和Arup两人会同时在车上一段时间,在Ayna在的时候,必须单曲循环Ayna喜欢的歌,偶数段Ayna下车,若此时已经放了她喜欢的那首歌,就要将 ...

  9. Benelux Algorithm Programming Contest 2019

    J. Jazz it Up!题目要求,n*m的因子中不能含有平方形式,且题目中已经说明n是一个无平方因子的数, 那么只要m是无平方因子的数,并且n和m没有共同的因子即可.要注意时间复杂度!代码:#in ...

随机推荐

  1. angularjs $state.go页面不刷新数据

    假如进入market/beian/add添加数据,保存提交后回退market/beian列表页,没有自动更新数据,必须得手动下拉刷新才会出来 $state.go("marketBeian&q ...

  2. Unity3d开发的第一个实例

    1.untiy3d开发环境配置好以后,开始我的第一个开发实例 2.在Hirearch---create---3DObject---Cube,在场景中创建一个正方体 3.project---create ...

  3. mysql配置jdbc

    jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://localhost:3306/database?useUnicode=t ...

  4. Compaq Visual Fortran生成静态库的方法及使用

    Compaq Visual Fortran 6.5生成lib静态库详细方法: 打开Compaq Visual Fortran,新建Fortran Static Library工程,命名为ForLib: ...

  5. UGUI的事件系统分析

    UGUI的源码还是非常清晰的,打开源码可以发现, 从UGUI的源码可知:在EventSystem中调用每一帧函数来实现: private void TickModules() { for (var i ...

  6. ssh登录卡住问题

    使用ssh登录远程centos服务器,卡住不动 系统centos 7 加-v查看登录过程,一直卡在这里 解决:我的是mtu问题 将eth0 mtu 默认1500修改为1200就可以了 ifconfig ...

  7. 【ML】聊天机器人

    继做过了泰语分词,自动对对对联后对聊天机器人产生了浓厚的兴趣.ChatBot集合了NLP,DL等多领域的应用. https://deeppavlov.ai/ https://www.rasa.com/ ...

  8. Portal的认证方式

    不同的组网方式下,可采用的 Portal 认证方式不同.按照网络中实施 Portal 认证的 网络层次来分,Portal 的认证方式分为两种:二层认证方式和三层认证方式. 二层认证方式.这种方式支持在 ...

  9. window下安装ubuntu(ubuntu可删除)

    进入ububtu13.04的安装界面,这里我们选择了“中文(简体)”,然后单击安装: 下图是现场拍的:   出现如下图时,请根据需要选择,然后单击“继续” , 接下来会出现问你是否要连接网络,我们选择 ...

  10. 利用Theano理解深度学习——Multilayer Perceptron

    一.多层感知机MLP 1.MLP概述 对于含有单个隐含层的多层感知机(single-hidden-layer Multi-Layer Perceptron, MLP),可以将其看成是一个特殊的Logi ...