码迷,mamicode.com
首页 > 其他好文 > 详细

焦作网络赛

时间:2018-09-15 22:28:53      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:判断   oid   popover   cal   nes   ==   cto   several   god   

J .

Jessie and Justin want to participate in e-sports. E-sports contain many games, but they don‘t know which one to choose, so they use a way to make decisions.

They have several boxes of candies, and there are ii candies in the i^{th}ith box, each candy is wrapped in a piece of candy paper. Jessie opens the candy boxes in turn from the first box. Every time a box is opened, Jessie will take out all the candies inside, finish it, and hand all the candy papers to Justin.

When Jessie takes out the candies in the N^{th}Nth box and hasn‘t eaten yet, if the amount of candies in Jessie‘s hand and the amount of candy papers in Justin‘s hand are both perfect square numbers, they will choose Arena of Valor. If only the amount of candies in Jessie‘s hand is a perfect square number, they will choose Hearth Stone. If only the amount of candy papers in Justin‘s hand is a perfect square number, they will choose Clash Royale. Otherwise they will choose League of Legends.

Now tell you the value of NN, please judge which game they will choose.

Input

The first line contains an integer T(1 \le T \le 800)T(1T800) , which is the number of test cases.

Each test case contains one line with a single integer: N(1 \le N \le 10^{200})N(1N10200) .

Output

For each test case, output one line containing the answer.

样例输入

4
1
2
3
4

样例输出

Arena of Valor
Clash Royale
League of Legends
Hearth Stone

题意 : 问你 n 是否是一个可开根数, 1-n-1求和是否是一个可开根数,判断输出即可

思路分析 : 套的JAVA牛顿迭代的板子

代码示例:

import java.math.BigInteger;
import java.math.*;
import java.math.BigInteger;
import java.util.Scanner;


import java.util.*; 
public class Main
{
    public static BigInteger bigSqrt(String s){
         Scanner cin=new Scanner(System.in);
          BigInteger remain=BigInteger.ZERO;
          BigInteger odd=BigInteger.ZERO;
          BigInteger ans=BigInteger.ZERO;
          int group=0,k=0;
          if(s.length()%2==1)
          {
                  group=s.charAt(0)-‘0‘;
                  k=-1;
          }
          else
          {
                  group=(s.charAt(0)-‘0‘)*10+s.charAt(1)-‘0‘;
                  k=0;
          }
          for(int j=0;j<(s.length()+1)/2;j++)
          {
                  if(j!=0)
                  group=(s.charAt(j*2+k)-‘0‘)*10+s.charAt(j*2+k+1)-‘0‘;
                  odd=BigInteger.valueOf(20).multiply(ans).add(BigInteger.ONE);
                  remain=BigInteger.valueOf(100).multiply(remain).add(BigInteger.valueOf(group));
                  int count=0;
                  while(remain.compareTo(odd)>=0)
                  {
                         count++;
                         remain=remain.subtract(odd);
                         odd=odd.add(BigInteger.valueOf(2));
                  }
                  ans=ans.multiply(BigInteger.TEN).add(BigInteger.valueOf(count));
          }
//          System.out.println(ans);
          
//        cin.close();
        return ans;
    }
       public static void main(String[] args) 
       {
    	   Scanner cin = new Scanner(System.in);
           int t;
   		   t = cin.nextInt();
   		   String s;
   		   BigInteger n;
   		   
   		   for(int i = 1; i <= t; i++) {
   			   n = cin.nextBigInteger() ;
   			   s = n.toString();
   			   BigInteger x = bigSqrt(s);
   			   BigInteger c1 = x.pow(2);
   			   int flag1 =  0;
   			   if (n.compareTo(c1) == 0) flag1 = 1;
   			   
   			   BigInteger m = n.subtract(BigInteger.ONE);
   			   BigInteger sum = n.multiply(m);
   			   BigInteger m2 = BigInteger.valueOf(2);
   			   sum = sum.divide(m2);
   			   s = sum.toString();
   			   x = bigSqrt(s) ;
   			   BigInteger c2 = x.pow(2);
   			   int flag2 =  0;
   			   if (sum.compareTo(c2) == 0) flag2 = 1;
   			   
   			if ((flag1 == 1) && (flag2 == 1)) System.out.println("Arena of Valor");
	        else if ((flag1 == 1) && (flag2 == 0)) System.out.println("Hearth Stone");
	        else if ((flag1 == 0) && (flag2 == 1)) System.out.println("Clash Royale");
	        else System.out.println("League of Legends");
   			   
   		   }

              cin.close();
      }
}

 

L .

God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous.

Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 333 continuous hours when he eats only one kind of food, he will be unhappy. Besides, if there are 333 continuous hours when he eats all kinds of those, with chocolate at the middle hour, it will be dangerous. Moreover, if there are 333 continuous hours when he eats meat or fish at the middle hour, with chocolate at other two hours, it will also be dangerous.

Now, you are the doctor. Can you find out how many different kinds of diet that can make God Water happy and safe during NNN hours? Two kinds of diet are considered the same if they share the same kind of food at the same hour. The answer may be very large, so you only need to give out the answer module 100000000710000000071000000007.

Input

The fist line puts an integer TTT that shows the number of test cases. (T≤1000T \le 1000T1000)

Each of the next TTT lines contains an integer NNN that shows the number of hours. (1≤N≤10101 \le N \le 10^{10}1N1010)

Output

For each test case, output a single line containing the answer.

样例输入

3
3
4
15

样例输出

20
46
435170
题意 : 有 3 种饮食,告诉你一些连续3天饮食搭配不健康的情况,问N天后饮食健康的方案有多少种?
思路分析 : 首先若只有两天的话,则有 9种情况,均符合要求,第三天再添加的时候纸上推一下,发现其实就是个 9*9的矩阵,一个矩阵快速幂即可
代码示例:

#define ll long long
const ll maxn = 1e6+5;
const ll mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const ll inf = 0x3f3f3f3f;

char s[1000];
struct mat
{
    ll a[15][15];
};
const ll modulu[15][15] = {
    {0, 0, 0, 1, 0, 0, 1, 0, 0},
    {1, 0, 0, 1, 0, 0, 1, 0, 0},
    {1, 0, 0, 1, 0, 0, 0, 0, 0},
    {0, 1, 0, 0, 1, 0, 0, 1, 0},
    {0, 1, 0, 0, 0, 0, 0, 1, 0},
    {0, 1, 0, 0, 1, 0, 0, 0, 0},
    {0, 0, 1, 0, 0, 0, 0, 0, 1},
    {0, 0, 0, 0, 0, 1, 0, 0, 1},
    {0, 0, 1, 0, 0, 1, 0, 0, 0}
};
ll n;
mat mul(mat a, mat b){
    mat r;
    memset(r.a, 0, sizeof(r.a));
     
    for(ll i = 0; i < 9; i++){
        for(ll j = 0; j < 9; j++){
            for(ll k = 0; k < 9; k++){
                r.a[i][j] += (a.a[i][k]*b.a[k][j])%mod;
                r.a[i][j] %= mod;           
            }
        }
    }
    return r;
}
 
mat qpow(mat a, ll x){
    mat b;
    memset(b.a, 0, sizeof(b.a));
    for(ll i = 0; i < 9; i++) b.a[i][i] = 1;
     
    while(x){
        if (x&1) b = mul(b, a);
        a = mul(a, a);
        x >>= 1;
    }
    return b;
}

int main() {
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    ll t;
    
    cin >> t;
    while(t--){
        cin >> n;
        mat a;
        memcpy(a.a, modulu, sizeof(modulu));
        if (n == 1) {printf("3\n"); continue;}
        else if (n == 2) {printf("9\n"); continue;}
        
        a = qpow(a, n-2);
        ll sum = 0;
        for(ll i = 0; i < 9; i++){
            for(ll j = 0; j < 9; j++){
                sum = (sum+a.a[i][j])%mod;
            }
        }
        printf("%lld\n", sum);
    }
    return 0;
}

 

焦作网络赛

标签:判断   oid   popover   cal   nes   ==   cto   several   god   

原文地址:https://www.cnblogs.com/ccut-ry/p/9652595.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!