Codeforces Round #792 (Div. 1 + Div. 2) 复盘

A. Digit Minimization

There is an integer nn without zeros in its decimal representation. Alice and Bob are playing a game with this integer. Alice starts first. They play the game in turns.

On her turn, Alice must swap any two digits of the integer that are on different positions. Bob on his turn always removes the last digit of the integer. The game ends when there is only one digit left.

You have to find the smallest integer Alice can get in the end, if she plays optimally.

Input

The input consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of test cases. Description of the test cases follows.

The first and the only line of each test case contains the integer n (10≤n≤109) — the integer for the game. n does not have zeros in its decimal representation.

Output

For each test case output a single integer — the smallest integer Alice can get in the end of the game.

Example

input

3
12
132
487456398

output

2
1
3

Note

In the first test case Alice has to swap 1 and 2. After that Bob removes the last digit, 1, so the answer is 2.

In the second test case Alice can swap 3 and 1: 312. After that Bob deletes the last digit: 31. Then Alice swaps 3 and 1: 13 and Bob deletes 3, so the answer is 1.

 思路分析:

考虑到交换位置,删除最后一个数位,依此类推的重复性操作,求得最小数。

根源在于:让最小数放到总是在交换中处于不被删除的位置,中间操作留给读者自己去想。我们写程序只需要保证最小数一直存在即可。

因此采取sort排序,输出s[0]即可。

但是有个问题,如果只有两个数位的数,由于数位分离小数位在前,而小数位在交换后已经处于s[0]的位置,因此分两种情况,两位的话,不排序输出s[0],结束本次操作,进入下一次操作。多于两位的话,排序,取得最小值,输出。 

代码实现:

#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int T;
	cin>>T;
	int a[101];
	while(T--){
	   int n;
	   cin>>n;
	   int k=0;
	   while(n){
	   	a[k]=n%10;
	   	k++;
	   	n/=10;
	   }
	   if(k==2){
	   	cout<<a[0]<<endl;
	   	continue;
	   }
	   sort(a,a+k);
	   cout<<a[0]<<endl;
	}
}

B. Z mod X = C 

 You are given three positive integers a, b, c (a<b<c). You have to find three positive integers x, y, z

such that:

x mod y=a,

y mod z=b,

z mod x=c.

Here p mod q

denotes the remainder from dividing p by q

. It is possible to show that for such constraints the answer always exists.

Input

The input consists of multiple test cases. The first line contains a single integer t

(1≤t≤10000) — the number of test cases. Description of the test cases follows.

Each test case contains a single line with three integers a, b, c (1≤a<b<c≤108).

Output

For each test case output three positive integers x, y, z (1≤x,y,z≤1018) such that x mod y=a,

y mod z=b, z mod x=c.

You can output any correct answer.

Example

Input

4
1 3 4
127 234 421
2 7 8
59 94 388

Output

12 11 4
1063 234 1484
25 23 8
2221 94 2609

Note

In the first test case:

x mod y=12 mod11=1;

y mod z=11 mod 4=3;  

z mod x=4 mod 12=4.

思路分析:

被除数%除数=模,

模+除数*商=被除数。

取特殊值,商为1.

除数+模=被除数。

例如,

c=c(最小)

(c)+b=b+c <=>(b+c )%c =b

(b+c)+a=a+b+c <=>(a+b+c)%(b+c)=a

代码实现: 

    #include<bits/stdc++.h>
    using namespace std;
     
    int main(){
    	int T;
    	cin>>T;
    	while(T--){
    		int a,b,c;
    		cin>>a>>b>>c;
    		cout<<a+b+c<<" "<<b+c<<" "<<c<<endl;
    	}
    	
    	
    		
    	
    }

 此题重在思路,想到特值法,其实取模的过程没必要去想,要想如何用有限的a,b,c构造出x,y,z。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值