D - Toll Road
Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87493#problem/D

Description

Exactly N years ago, a new highway between two major cities was built. The highway runs from west to east. It was planned as one big segment of a toll road. However, new highway was not popular: drivers still used free roads.

After analyzing the situation, the administration decided to perform a marketing trick to increase the popularity of the new highway.

The highway was divided into segments. Initially, there was only one segment. Every odd year, each of the existing segments was divided into two new segments with lengths divided as X: Y. This means that the length of the western segment relates to the length of the eastern segment as X relates to Y. Every even year, each of the existing segments was also divided into two new segments, but this time, the ratio was Y: X. After each division, the first of the two resulting segments was declared a free road and the second one a toll road. Each year, the segments are numbered from 1 from west to east. For simplicity, X and Y are positive integers which sum up to exactly 100.

As a result, the administration was able to significantly increase the income: the drivers started to drive on free segments and did not dare to turn away at the sight of the next toll segment. But after N years, the plan of the highway became so complex that it is now hard to calculate the exact lengths of the segments.

Knowing the total length of the highway P, one can calculate the length Lk of the segment with number k using the formula

Lk = P × (X / 100)Ak × (Y / 100)Bk

for some integers Ak and Bk. Here, Ak is the number of years in which, during the division, this segment was in the part proportional toX, and Bk is the number of years when it was in the part proportional to Y.

You need to answer to the queries containing numbers Ki of segments. To answer each query, you must print the values of Aki and Bkifor the corresponding segment.

 

Input

The first line of the input contains three integers: the number of years N (1 ≤ N ≤ 1018) that have elapsed since the highway was built, followed by the percentages X and Y (1 ≤ X, Y ≤ 99, X + Y = 100) used each year to divide the segments.

The second line contains one integer: the number of queries Q (1 ≤ Q ≤ 104).

The following Q lines contain queries. Each query is an integer Ki (1 ≤ Ki ≤ 1018), the number of some segment. It is guaranteed that the segment with such number exists.

Output

For each query, print two integers Aki and Bki on a separate line.

Sample Input

3 25 75 4
1
3
5
8

Sample Output

2 1
3 0
1 2
1 2

HINT

题意

前面全是废话

给你一个二叉树,第i层,第k个节点,如果(i+k)%2==0,那么这个节点就是A,否则节点就是B

Q次询问,每次问你第n层的第x节点,如果一直往上面爬,爬到第1层第1个节点,一共经历了几次A,几次B

题解

首先O(层数)的做法很明显是不可行的,应该要O(log)的,很容易发现,往上面爬和在同层次往左边爬是一样的

所以我们log爬到同层的第一个,然后再O(1)计算就好了

代码:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <string>
#include <ctime>
#include <list>
#include <bitset>
typedef unsigned char byte;
#define pb push_back
#define input_fast std::ios::sync_with_stdio(false);std::cin.tie(0)
#define local freopen("in.txt","r",stdin)
#define pi acos(-1) using namespace std; int C(long long x,long long y)
{
if(x%==)
{
if(y%==)
return ;
else
return ;
}
else
{
if(y%==)
return ;
else
return ;
}
}
int main()
{
long long n;
long x1,x2,q;
cin>>n>>x1>>x2>>q;
for(int i=;i<q;i++)
{
long long t1 = n;
long long t2;
scanf("%lld",&t2);
long long ans1=,ans2=;
while()
{
if(C(t1,t2)==)
ans1++;
else
ans2++;
if(t2==1LL||t1==1LL)
break;
t2=(t2+1LL)/2LL;
t1--;
}
t1--;
if(t1!=)
{
ans1+=t1/2LL;
ans2+=t1/2LL;
if(t1%2LL==1LL)
{
if(C(t1,t2)==)
ans1++;
else
ans2++;
} }
printf("%lld %lld\n",ans1,ans2);
}
}

Codeforces Gym 100425D D - Toll Road 找规律的更多相关文章

  1. Codeforces Gym 100114 A. Hanoi tower 找规律

    A. Hanoi tower Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100114 Descript ...

  2. codeforces Gym 100418D BOPC 打表找规律,求逆元

    BOPCTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?c ...

  3. Codeforces Gym 100015A Another Rock-Paper-Scissors Problem 找规律

    Another Rock-Paper-Scissors Problem 题目连接: http://codeforces.com/gym/100015/attachments Description S ...

  4. Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...

  5. Gym 101981G - Pyramid - [打表找规律][2018-2019 ACM-ICPC Asia Nanjing Regional Contest Problem G]

    题目链接:http://codeforces.com/gym/101981/attachments The use of the triangle in the New Age practices s ...

  6. Codeforces H. Malek Dance Club(找规律)

    题目描述: Malek Dance Club time limit per test 1 second memory limit per test 256 megabytes input standa ...

  7. [CodeForces - 848B] Rooter's Song 思维 找规律

    大致题意: 有一个W*H的长方形,有n个人,分别站在X轴或Y轴,并沿直线向对面走,第i个人在ti的时刻出发,如果第i个人与第j个人相撞了 那么则交换两个人的运动方向,直到走到长方形边界停止,问最后每个 ...

  8. codeforces 622D D. Optimal Number Permutation(找规律)

    D. Optimal Number Permutation time limit per test 1 second memory limit per test 256 megabytes input ...

  9. 【Codeforces 707C】Pythagorean Triples(找规律)

    一边长为a的直角三角形,a^2=c^2-b^2.可以发现1.4.9.16.25依次差3.5.7.9...,所以任何一条长度为奇数的边a,a^2还是奇数,那么c=a^2/2,b=c+1.我们还可以发现, ...

随机推荐

  1. 构造函数后面的base()

    先执行父类的对应的构造函数,再执行当前的构造函数. 关于子类对象的构造函数和父类构造函数的执行顺序 以下内容转自:http://blog.csdn.net/todototry/article/deta ...

  2. Oracle DBA 的常用Unix参考手册(一)

    作为一名Oracle DBA,在所难免要接触Unix,但是Unix本身又是极其复杂的,想要深刻掌握同样很不容易.那么到底我们该怎么入手呢?Donald K Burleson 的<Unix for ...

  3. Android-AnimationDrawable(三)运行的几种方式

    项目开发用到了AnimationDrawable,调用start后没有运行,很纳闷.google搜了下.记录一下. 这个AnimationDrawable.start不能直接写在onClick,onS ...

  4. java web 学习十二(session)

    一.Session简单介绍 在WEB开发中,服务器可以为每个用户浏览器创建一个会话对象(session对象),注意:一个浏览器独占一个session对象(默认情况下).因此,在需要保存用户数据时,服务 ...

  5. NumberSeekBar 可任意拖动和自动

    package com.example.numberseekbar; import android.content.Context; import android.content.res.Resour ...

  6. iOS 怎么样给自己的app打分呢?

    NSString *str =  [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/id%@",@&quo ...

  7. [Tommas] 测试用例覆盖率(三)

    三.测试数据的设计 每一个测试思路最终都要转化成具体的数据才能来执行.关于测试数据设计的方法也不外乎那几种,就不再赘述了.此处单就一些经常易犯的错误,提出一些注意点,作为用例数据设计时的参考: 1.尽 ...

  8. 【算法与数据结构】字符串匹配之KMP算法

    // KMP.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream> #include < ...

  9. GCC4.8对new和delete的参数匹配新要求

    一段通信协议的代码,早年在GCC 4.4.VS2013下编译都挺好的,移植到GCC 4.8 ,为C++ 11做准备,在编译的时候发现问题 源代码省略后的版本如下: class Zerg_App_Fra ...

  10. 并行开发——Parallel的使用 -摘自网络

    随着多核时代的到来,并行开发越来越展示出它的强大威力,像我们这样的码农再也不用过多的关注底层线程的实现和手工控制, 要了解并行开发,需要先了解下两个概念:“硬件线程”和“软件线程”. 1. 硬件线程 ...