51NOD 1185 Witzov Game V2 (game theory + reduced accuracy)

Source: Internet
Author: User

Transmission Door
There are 2 piles of stones. A B Two people take turns, a take first. Each time you can take any or 2 of the same number of stones from a heap, but not to be taken. The man who got the last 1 stones won. Suppose a B is very clever, there is no mistake in the process of taking the stone. Give the number of 2 stones and ask who will win the game at the end.
For example, 2 stones were 3 and 5. So no matter a how to take, B has a corresponding method to get the last 1.
Input
Line 1th: A number t that represents the number of numbers that are later used as input tests. (1 <= T <= 10000)
Section 2-t + 1 lines: 2 numbers per row are 2 piles of stones, separated by spaces. (1 <= N <= 10^18)
Output
A total of T-lines, if a WINS output A, if B wins output B.
Input example
3
3 5
3 4
1 9
Output example
B
A
A
Problem Solving Ideas:
If the range of data in this topic is not very large, multiply it directly. (sq RT(5)+1) 2 On the line, but in this topic, the data range is too large, if the direct multiplication will have a precision problem, so we reduce the accuracy problem, will 0.618033988749894848204586834 ... Split the integer into the array, split it into three parts, and then multiply to reduce the loss of precision. See the code specifically:
< Span class= "Mrow" id= "mathjax-span-1146" >m y Span style= "Display:inline-block; width:0px; Height:2.616em; " > Code

#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace STD;typedef Long LongLL; LL tmp[3] = {618033988,749894848,204586834}; LL MOD =1000000000;intMain () {intT LL m, N;Cin>>T; while(t--) {Cin>>m>>n;if(M < n) swap (n, m);        LL cha = m-n;        LL ta = cha/mod, TB = cha%mod; LL TP = tb*tmp[2]; TP = ta*tmp[2] + tb*tmp[1] + tp/mod; TP = ta*tmp[1] + tb*tmp[0] + tp/mod; TP = Cha + ta*tmp[0] + tp/mod;if(tp = = N)puts("B");Else            puts("A"); }return 0;}

51NOD 1185 Witzov Game V2 (game theory + reduced accuracy)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.