CF1525

A

题面

You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k   % k\ \% k %magic essence and ( 100 − k )   % (100 - k)\ \% (100k) % water.

In one step, you can pour either one liter of magic essence or one liter of water into the cauldron. What is the minimum number of steps to brew a potion? You don’t care about the total volume of the potion, only about the ratio between magic essence and water in it.

A small reminder: if you pour e e e liters of essence and w w w liters of water ( e + w > 0 e + w > 0 e+w>0 ) into the cauldron, then it contains e e + w ⋅ 100   % \frac{e}{e + w} \cdot 100\ \% e+we100 % (without rounding) magic essence and w e + w ⋅ 100   % \frac{w}{e + w} \cdot 100\ \% e+ww100 % water

翻译

t t t ( 1 ≤ t ≤ 100 ) (1\le t\le100) (1t100)组数据,每组数据输入一个数 k k k ( 1 ≤ k ≤ 100 ) (1\le k\le 100) (1k100)
输出至少要多少份的液体(两种相加)使浓度到 k % k\% k%

解析

可以发现无论如何, a n s w e r ≤ 100 answer\le100 answer100
而当它小于 100 100 100时,一定是 k k k 100 − k 100-k 100k有公因数时;
所以 a n s w e r = 100 g c d ( k , 100 − k ) answer=\frac{100}{gcd(k,100-k)} answer=gcd(k,100k)100

代码

#include<bits/stdc++.h>
using namespace std;
int T,N;
int gcd(int a,int b){return (b>a?b^=a^=b^=a:0),b?gcd(b,a%b):a;}
int main(){
	scanf("%d",&T);
	while(T--){scanf("%d",&N);printf("%d\n",100/gcd(N,100-N));}
	return 0;
}

B

题面

You are given a permutation aa consisting of nn numbers 1 1 1 , 2 2 2 , …, n n n (a permutation is an array in which each element from 1 1 1 to n n n occurs exactly once).

You can perform the following operation: choose some subarray (contiguous subsegment) of aa and rearrange the elements in it in any way you want. But this operation cannot be applied to the whole array.

For example, if a = [ 2 , 1 , 4 , 5 , 3 ] a = [2, 1, 4, 5, 3] a=[2,1,4,5,3] and we want to apply the operation to the subarray a [ 2 , 4 ] a[2, 4] a[2,4] (the subarray containing all elements from the 2 n d 2^{nd} 2nd to the 4 t h 4^{th} 4th), then after the operation, the array can become a = [ 2 , 5 , 1 , 4 , 3 ] a = [2, 5, 1, 4, 3] a=[2,5,1,4,3] or, for example, a = [ 2 , 1 , 5 , 4 , 3 ] a = [2, 1, 5, 4, 3] a=[2,1,5,4,3]
task is to calculate the minimum number of operations described above to sort the permutation aa in ascending order.

翻译

T T T ( 1 ≤ T ≤ 2000 ) (1\le T\le 2000) (1T2000)组数据,给定一个长度为 N N N ( 3 ≤ N ≤ 50 ) (3\le N \le 50) (3N50)的序列,有 1 − N 1-N 1N, N N N个数字,每次可以把一个小于 N N N的连续区间中进行排序,问要几次后才能使序列有序

解析

可以发现,每次排序后最多可以把除去首尾的任意一个外的其他排序,就可以分类讨论:

条件结论
a i = i ( 1 ≤ i ≤ N ) a_i=i(1\le i\le N) ai=i(1iN)0
a 1 = 1 a_1=1 a1=11
a N = N a_N=N aN=N1
a 1 = N , a N = 1 a_1=N,a_N=1 a1=N,aN=13
others2

代码

#include <bits/stdc++.h>
using namespace std;
int a[139];
int N,T;
void print(int x){printf("%d\n",x);}
int main() {
    scanf("%d",&T);
    while(T--){
	    bool f=1;scanf("%d",&N);
	    for(int i=1;i<=N;i++) {scanf("%d",&a[i]);if(a[i]!=i){f = 0;}}
	    if(f){print(0);} else if(a[1]==1||a[N]==N){print(1);} else if(a[1]==N&&a[N]==1){print(3);} else{print(2);}
  }
  return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值