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 ...
随机推荐
- 框架使用-Sql拼接
Sql语句拼写: 查询 DQueryDom DmoQuery(返回的整个对象) 更新 DQUpdateDom 删除 DQDeleteDom 条件 dom.Where.Conditions.Add(D ...
- 转---JS 获取鼠标左右键
原文:http://blog.csdn.net/mine3333/article/details/7291557 function test() { alert(event.x+" &quo ...
- iOS开发ReactiveCocoa学习笔记(六)
RAC操作方法三. demo地址:https://github.com/SummerHH/ReactiveCocoa.git doNext deliverOn timeout interval del ...
- 微信小程序:点击预览图片
在开发微信小程序时,开发人员会参考着小程序api来开发小程序,但有的时候根据情况不同很容易出现bug,以下是我在开发小程序时出现的各种bug,在开发时有需要预览图片. 1.xml <view c ...
- socket网络套节字---聊天室
一:服务端: 1.创建客户端: package com.ywh.serversocket; import java.io.InputStream; import java.io.OutputStrea ...
- C# 获取当前文件、文件夹的路径及操作环境变量
一.获取当前文件的路径 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包 ...
- 不该被忽视的CoreJava细节(三)
一.不该被遗忘的移位位运算 本文主要介绍移位运算(Shift Operation), 适当介绍一下其它相关的位运算. 甭说计算机刚发明那会,就连21世纪初那段日子,计算机内存都是KB/MB计算的.编写 ...
- Git 推送和删除标签
事实上Git 的推送和删除远程标签命令是相同的,删除操作实际上就是推送空的源标签refs:git push origin 标签名相当于git push origin refs/tags/源标签名:re ...
- 为Visual Studio 2012添加MSDN离线帮助
之前有网络的情况下,一直使用的都是在线的,最近又有笔记本上面有时使用时没有网络,所以就想使用下离线的MSDN包.可是找了半天,发现都是需要再次进行下载的.VS2012使用的帮助程序是HelpViewe ...
- 提升Web性能的8个技巧总结
提升Web性能的8个技巧总结 在互联网盛行的今天,越来越多的在线用户希望得到安全可靠并且快速的访问体验.针对Web网页过于膨胀以及第三脚本蚕食流量等问题,Radware向网站运营人员提出以下改进建议, ...