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 ...
随机推荐
- Visual Studio中的引用项目和直接引用DLL文件
在VS中引用类库时有多种方法,其中用的最多的就是在引用时选择项目选项卡引用本解决方案下的类库项目和选择浏览选项卡直接引用类库DLL文件,实际上这两种引用方式略有不同,今天就为大家总结下. C#本地项目 ...
- JavaFX上手--第1天
1.第一个JavaFX Application JavaFX 使用Java来制作可视化图形,可以做动画和3D效果,JavaFX从JDK中直接使用. package application; impor ...
- elasticsearch报错:None of the configured nodes are available: []
问题:在内网测试的时候可以正常访问,但是部署到外网上客户端连接elasticsearch报错:None of the configured nodes are available: [] 原因:默认情 ...
- 在sublime text3下,用快捷键把文件打开到浏览器中
使用背景 在编辑html或者js文件的时候,是否想在浏览器中预览一下, 你的步骤可能是这样的: 找到编辑文件的位置, 右键使用某一浏览器打开.如果是这样,你就out了, 因为在sublime中有更加简 ...
- 【Oracle】曾经的Oracle学习笔记(4-7)多表联合查询,子查询,动态条件查询
一.多表联合查询 二.子查询 三.动态条件查询 LESSON 4 Displaying Data from Multiple Tables------------------------------- ...
- 查询MySQL的存储引擎
- pta 编程题13 File Transfer
其它pta数据结构编程题请参见:pta 这道题考察的是union-find并查集. 开始把数组中每个元素初始化为-1,代表没有父节点.为了使树更加平衡,可以让每一个连通分量的树根的负值代表这个连通分量 ...
- linux 命令——51 lsof(转)
lsof(list open files) 是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.所以 如传输控制 ...
- 在Spark集群中,集群的节点个数、RDD分区个数、cpu内核个数三者与并行度的关系
梳理一下Spark中关于并发度涉及的几个概念File,Block,Split,Task,Partition,RDD以及节点数.Executor数.core数目的关系. 输入可能以多个文件的形式存储在H ...
- 2018.10.29 NOIP2018模拟赛 解题报告
得分: \(70+60+0=130\)(\(T3\)来不及打了,结果爆\(0\)) \(T1\):简单的求和(点此看题面) 原题: [HDU4473]Exam 这道题其实就是上面那题的弱化版,只不过把 ...