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. Windows Phone 离主流系统还很远

    调查机构 Kantar Worldpanel 在本月发布全球智能手机份额报告.报告显示,五月份除德国和澳大利亚出现下滑,Windows Phone 的市场份额在不少国家都实现增长. 英国,4.1% 升 ...

  2. C# DataGridView的列对象属性探讨 (未完待续)

    比较难的几个属性的释义[1]:

  3. linux命令——rmdir

    rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.rm - r dir命令可代替rmdir rmdir [选项]... 目录... - p 递归删除目录dirname,当 ...

  4. kmeans算法的matlab实践

    把图像中所有的像素点进行RGB聚类分析,然后输出看结果 img = imread('qq.png'); %取出R矩阵,并将这个R矩阵拉成一列 imgR = img(:,:,1); imgR = img ...

  5. [GRYZ2015]Graph

    题目描述 给出 N 个点,M 条边的有向图,对于每个点 v,求 A(v) 表示从点 v 出发,能到达的编号最大的点. 输入格式 第 1 行,2 个整数 N,M. 接下来 M 行,每行 2 个整数 Ui ...

  6. ORA-15041: diskgroup space exhausted

    今天在做一个备份的时候,出现磁盘耗尽的错误,具体如下: RMAN-00571: =========================================================== ...

  7. QT-【转】Qt 4迁移至Qt 5

    将Qt 4代码迁移到Qt 5还是比较简单的.实际上,在Qt 5开发过程中就已经注意了与Qt 4代码保持兼容性. 与Qt 3到Qt 4的迁移不同,Qt 5的核心类库并没有做大的API的修改,只有几个新的 ...

  8. linux 用 SSH2协议远程连接并控制 linux

    [参考链接](http://php.net/manual/zh/ssh2.installation.php) ssh2_exec 并不能打印所有的命令的提示信息 如果有返回的字符串信息,可以打印,或重 ...

  9. wuzhicms 后台登录存留时间实现方式

    在五指后台管理登录后,超过半小时不操作后台(不刷新页面或切换页面),就就会强制退出后台. 实现的思路是,在每次刷新页面都把当前时间存储下来,利用php的session机制来检测比对当前时间和数据库中存 ...

  10. Tkinter教程之Button篇(2)

    本文转载自:http://blog.csdn.net/jcodeer/article/details/1811300 # Tkinter教程之Button篇(2)'''5.指定Button的宽度与高度 ...