第二次习题2020.5.22

A - Candies

Recently Vova found nn candy wrappers. He remembers that he bought xx candies during the first day, 2x2x candies during the second day, 4x4x candies during the third day, ……, 2k−1x2k−1x candies during the kk-th day. But there is an issue: Vova remembers neither xx nor kk but he is sure that xx and kk are positive integers and k>1k>1.
Vova will be satisfied if you tell him any positive integer xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n. It is guaranteed that at least one solution exists. Note that k>1k>1.
You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (3≤n≤1093≤n≤109) — the number of candy wrappers Vova found. It is guaranteed that there is some positive integer xx and integer k>1k>1 that x+2x+4x+⋯+2k−1x=nx+2x+4x+⋯+2k−1x=n.

Output

Print one integer — any positive integer value of xx so there is an integer k>1k>1 that x+2x+4x+⋯+2k−1x=n

在这里插入图片描述

题意

t个样例,给出n根据已知的数学关系,求x,k。

思路

将x提出根据关系3<=n<=10^9。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--){
        int n,k,x,s;
        cin>>n;
        s=3;		//从第三项开始,前两项和为3.
        k=1;
        while(n%s!=0){
            k++;
            s=s+pow(2,k);
        }
        x=n/s;
        cout<<x<<endl;
    }
}

B - Balanced Array

You are given a positive integer nn, it is guaranteed that nn is even (i.e. divisible by 22).
You want to construct the array aa of length nn such that:

The first n2n2 elements of aa are even (divisible by 22);
the second n2n2 elements of aa are odd (not divisible by 22);
all elements of aa are distinct and positive;
the sum of the first half equals to the sum of the second half (∑i=1n2ai=∑i=n2+1nai∑i=1n2ai=∑i=n2+1nai).

If there are multiple answers, you can print any. It is not guaranteed that the answer exists.
You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases. Then tt test cases follow.
The only line of the test case contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the length of the array. It is guaranteed that that nn is even (i.e. divisible by 22).
It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052⋅105 (∑n≤2⋅105∑n≤2⋅105).

Output

For each test case, print the answer — “NO” (without quotes), if there is no suitable answer for the given test case or “YES” in the first line and any suitable array a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) satisfying conditions from the problem statement on the second line.

Example

Input
5
2
4
6
8
10
Output
NO
YES
2 4 1 5
NO
YES
2 4 6 8 1 3 5 11
NO

题意

t个样例,给出一个偶数n,前n/2个数为偶数后n/2为奇数,前后两部分和相等。如果存在这样的数组输出YES。

思路

如果n/2是奇数前一部分为偶数后部分为奇数不成立。反之从2开始将前n/2个偶数写满,接着对后半部分从1输入奇数前n/2-1最后一项用偶数和减去其它奇数和。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
    int n,i,j;
    cin>>n;
    int a[n+1],sum1=2,sum2=1;
    a[1]=2;
    a[n/2+1]=1;
    if(n%4!=0)cout<<"NO"<<endl;
    else{
        for(i=2;i<=n/2;i++){
            a[i]=a[i-1]+2;
            sum1+=a[i];
        }
        for(j=n/2+2;j<n;j++){
            a[j]=a[j-1]+2;
            sum2+=a[j];
        }
        a[n]=sum1-sum2;
        cout<<"YES"<<endl;
        cout<<a[1];
        for(i=2;i<n+1;i++){
        cout<<" "<<a[i];
        }
        cout<<endl;
    }
   }
}

C - Ichihime and Triangle

Ichihime is the current priestess of the Mahjong Soul Temple. She claims to be human, despite her cat ears.
These days the temple is holding a math contest. Usually, Ichihime lacks interest in these things, but this time the prize for the winner is her favorite — cookies. Ichihime decides to attend the contest. Now she is solving the following problem.
You are given four positive integers aa, bb, cc, dd, such that a≤b≤c≤da≤b≤c≤d.
Your task is to find three integers xx, yy, zz, satisfying the following conditions:

a≤x≤ba≤x≤b.
b≤y≤cb≤y≤c.
c≤z≤dc≤z≤d.
There exists a triangle with a positive non-zero area and the lengths of its three sides are xx, yy, and zz.

Ichihime desires to get the cookie, but the problem seems too hard for her. Can you help her?

Input

The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The next tt lines describe test cases. Each test case is given as four space-separated integers aa, bb, cc, dd (1≤a≤b≤c≤d≤1091≤a≤b≤c≤d≤109).

Output

For each test case, print three integers xx, yy, zz — the integers you found satisfying the conditions given in the statement.
It is guaranteed that the answer always exists. If there are multiple answers, print any.

Example

Input
4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810
Output
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810

题意

在a<=b<=c<=d,x,y,z属于(a,b)(b,c)(c,d),求一个三角形边长为x,y,z。

思路

只要构造一个等腰三角形,并且两个腰相加一定大于底。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
    int x,y,z,a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<b<<" "<<c<<" "<<c<<endl;	//如果采用bbc,有可能b+b<c。
   }
}

D - Kana and Dragon Quest game

Kana was just an ordinary high school girl before a talent scout discovered her. Then, she became an idol. But different from the stereotype, she is also a gameholic. One day Kana gets interested in a new adventure game called Dragon Quest. In this game, her quest is to beat a dragon. The dragon has a hit point of xx
initially. When its hit point goes to 00or under 00, it will be defeated. In order to defeat the dragon, Kana can cast the two following types of spells. Void Absorption Assume that the dragon’s current hit point is hh, after casting this spell its hit point will become ⌊h2⌋+10⌊h2⌋+10. Here ⌊h2⌋⌊h2⌋denotes hh divided by two, rounded down. Lightning Strike This spell will decrease the dragon’s hit point by 1010

. Assume that the dragon’s current hit point is hh

, after casting this spell its hit point will be lowered to h−10h−10

.Due to some reasons Kana can only cast no more than nnVoid Absorptions and mm

Lightning Strikes. She can cast the spells in any order and doesn’t have to cast all the spells. Kana isn’t good at math, so you are going to help her to find out whether it is possible to defeat the dragon.

Input

The first line contains a single integer tt

(1≤t≤10001≤t≤1000) — the number of test cases.The next tt

lines describe test cases. For each test case the only line contains three integers xx
, nn, mm(1≤x≤1051≤x≤105, 0≤n,m≤300≤n,m≤30) — the dragon’s intitial hit point, the maximum number of Void Absorptions and Lightning Strikes Kana can cast respectively.

Output

If it is possible to defeat the dragon, print “YES” (without quotes). Otherwise, print “NO” (without quotes).You can print each letter in any case (upper or lower).

Example

Input
7
100 3 4
189 3 4
64 2 3
63 2 3
30 27 7
10 9 1
69117 21 2
Output
YES
NO
NO
YES
YES
YES
YES

题意

巨龙血量h,有两个技能,一种巨龙血量变为h/2+10可用n次,另一种h-10可用m次。

思路

考虑两种情况一种h足够小第二种技能足够杀死,否则考虑先用一技能消耗最后判断二技能能否终结。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
   int x,n,m;
   cin>>x>>n>>m;
   if(x<=m*10)cout<<"YES"<<endl;	//判断是否二技能直接击败巨龙。
   else{
   while(n--){
    x=x/2+10;
   }
   if(x>m*10)cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
   }}
}

E - Candies and Two Sisters

There are two sisters Alice and Betty. You have nn

candies. You want to distribute these nn

candies between two sisters in such a way that: Alice will get aa

(a>0a>0

) candies; Betty will get bb

(b>0b>0

) candies; each sister will get some integer number of candies; Alice will get a greater amount of candies than Betty (i.e. a>ba>b

); all the candies will be given to one of two sisters (i.e. a+b=na+b=n

). Your task is to calculate the number of ways to distribute exactly nn

candies between sisters in a way described above. Candies are indistinguishable.Formally, find the number of ways to represent nn

as the sum of n=a+bn=a+b

, where aa

and bb

are positive integers and a>ba>b

.You have to answer tt

independent test cases.

Input

The first line of the input contains one integer tt

(1≤t≤1041≤t≤104

) — the number of test cases. Then tt

test cases follow.The only line of a test case contains one integer nn

(1≤n≤2⋅1091≤n≤2⋅109

) — the number of candies you have.

Output

For each test case, print the answer — the number of ways to distribute exactly nn

candies between two sisters in a way described in the problem statement. If there is no way to satisfy all the conditions, print 00.

Example

Input
6
7
1
2
3
2000000000
763243547
Output
3
0
0
1
999999999
381621773

题意

t个样例,两姐妹分糖果,a>b,a+b=n.a!=0,b!=0。总共多少种分法。

思路

如果n是1,2无法分输出0,除此之外之需要考虑平分妹妹的糖果最多有多少。就有几种分法。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
    int n;
   cin>>n;
   if(n==1||n==2)cout<<"0"<<)ndl;	//1,2特例。
   else if(n%2!=0)cout<<n/2<<endl;	//n为奇数直接除二得出结果(小数保留整数)
   else cout<<n/2-1<<endl;		//偶数平分除去相等的情况。
  }
}
             

F - Construct the String

You are given three positive integers nn

, aa

and bb

. You have to construct a string ss

of length nn

consisting of lowercase Latin letters such that each substring of length aa

has exactly bb

distinct letters. It is guaranteed that the answer exists.You have to answer tt

independent test cases.Recall that the substring s[l…r]s[l…r]

is the string sl,sl+1,…,srsl,sl+1,…,sr

and its length is r−l+1r−l+1

. In this problem you are only interested in substrings of length aa.

Input

The first line of the input contains one integer tt

(1≤t≤20001≤t≤2000

) — the number of test cases. Then tt

test cases follow.The only line of a test case contains three space-separated integers nn

, aa

and bb

(1≤a≤n≤2000,1≤b≤min(26,a)1≤a≤n≤2000,1≤b≤min(26,a)

), where nn

is the length of the required string, aa

is the length of a substring and bb

is the required number of distinct letters in each substring of length aa

.It is guaranteed that the sum of nn

over all test cases does not exceed 20002000

(∑n≤2000∑n≤2000

).

Output

For each test case, print the answer — such a string ss

of length nn

consisting of lowercase Latin letters that each substring of length aa

has exactly bb

distinct letters. If there are multiple valid answers, print any of them. It is guaranteed that the answer exists.
Example
Input
4
7 5 3
6 1 1
6 6 1
5 2 2
Output
tleelte
qwerty
vvvvvv
abcde

题意

t个样例,字符串长度为n,取连续a个字符,字符种类有b个。

思路

创建循环为b长度的子字符串连续输出n长度。

代码

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
   int t;
   cin>>t;
   while(t--){
    int n,a,b,i;
    char sim='a';
    cin>>n>>a>>b;
    char model[b+1],s[n+1];
    for(i=1;i<=b;i++){
        model[i]=sim;	//循环子字符串。
        sim++;
    }
    for(i=1;i<=n;i++){
        if(i%b==0){
            s[i]=model[b];	//取余b为0等于b项。
        }
        else{
            s[i]=model[i%b];
        }
    }
    for(i=1;i<=n;i++){
        cout<<s[i];
    }
    cout<<endl;
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: "130道python练习题.zip"是一个包含130道Python练习题目的压缩文件。这个文件可能包括若干个Python脚本文件或文本文件,在这些文件中分别包含了不同的练习题。由于题目的数量较多,这份练习题压缩文件可能对于想要提高Python编程技能的学习者或者需要参加Python编程考试的人非常有帮助。 通过这份压缩文件,学习者可以利用Python解决不同难度级别的问题,提高他们的编码能力和解决问题的能力。这些练习题可以涵盖Python语言的各个方面,包括基本的语法、数据类型、循环、条件语句、函数、文件操作等。通过实践,学习者可以更好地理解和掌握Python编程语言的各种知识点。 对于想要提高自己的编程能力的人来说,这份练习题压缩文件是一个非常宝贵的学习资源。通过完成这些题目,他们可以积累编程经验,提高自己的逻辑思维和问题解决能力。同时,这些练习题也可以用于培训机构或教育机构的Python编程课程,帮助学生掌握Python编程的基本技能和解决问题的能力。 总之,"130道python练习题.zip"是一个包含了130道Python练习题的压缩文件,对于想要提高Python编程技能的学习者或者需要参加Python编程考试的人来说,是一个非常有价值的资源。通过完成这些练习题,他们可以提高编程水平,增强逻辑思维和问题解决能力。 ### 回答2: "130道Python练习题.zip" 是一个压缩文件,其中包含了130个Python编程练习题的集合。这些练习题旨在帮助学习和提高Python编程的技能。每个练习题都配有详细的题目描述和要求,让学习者能够逐步解决问题并提供相应的解决方案。 通过完成这些练习题,学习者能够提高对Python语法和编程概念的理解,并锻炼自己的编程能力。题目难度不断递增,从基础的语法练习到更复杂的算法和数据结构的应用。通过反复练习,学习者能够巩固自己的知识并且提高代码的效率和优雅度。 这个练习题的压缩文件是一个方便的资源,可以按照自己的进度和需求进行学习。学习者可以用任何文本编辑器打开题目,编写自己的解答,并且与提供的解决方案进行对比。 练习编程对于掌握Python及其他编程语言非常重要。通过解决这些练习题,学习者能够提高解决问题的能力和分析思维,并致力于成为一个优秀的Python程序员。 总结来说,"130道Python练习题.zip"是一个提供练习编程能力和理解Python编程语言的资源。通过完成这些练习题,学习者可以提高自己的编程水平,提升对Python及编程概念的理解,培养解决问题的能力,并且成为一个更出色的Python程序员。 ### 回答3: 130道python练习题.zip是一个包含了130个Python练习题目的压缩文件。这些练习题目旨在帮助学习者进一步熟悉和掌握Python编程语言。 这个压缩文件中的题目类型各异,涉及了Python的各个方面,从基础的语法理解到进阶的算法和数据结构,都有涵盖。通过解决这些练习题,学习者可以提高他们的编码能力和问题解决能力,并且扩展他们对Python编程语言的理解。 解压缩该文件后,可以得到130个独立的Python文件,每个文件对应一个题目。在每个文件中,包含了问题的具体描述以及必要的输入输出示例。学习者需要仔细阅读问题描述,并编写代码来解决问题。他们可以使用任意编程编辑器来编写代码,并通过运行代码来检验答案是否正确。 通过解答这些题目,学习者将深入了解Python编程语言的许多方面,例如变量、数据类型、条件语句、循环语句、函数、文件操作、异常处理、模块和包等等。此外,这些练习题还会引导学习者思考问题的解决方法,培养逻辑思维和编程思维。完成这些练习题之后,学习者将能够在Python编程方面更加独立和自信。 总之,130道python练习题.zip提供了一个丰富而全面的学习资源,适用于想要提高Python编程能力的学习者。通过解答这些题目,学习者可以加深对Python的理解,并提高编程技巧和问题解决能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值