Educational Codeforces Round 109 (Rated for Div. 2)(A-B)

简介: 算法

链接


A. Potion-making


题意:大概就是啤酒兑水的问题,要求你对完之后酒精的浓度可以达到k,然后众所周知加一升的水,浓度就会降,加一升酒精就会升(你不是废话吗? ),求最少要加多少升酒精和水。


思路:其实细想一下如果要25的浓度其实就是25/100=1/4,

而要10的浓度是10/100,约分一下就是1/10。

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,t;
    cin>>t;
    while(t--){
            cin>>n;
            int d1=__gcd(100,n);
            cout<<max(n/d1,100/d1)<<endl;
    }
    return 0;
}


B. Permutation Sort


题意:一堆打乱的序列,问你需要进行多少次洗牌式处理能还原正常序列,不能对整个序列进行洗牌操作。

思路:三种情况

①已经排好----ans=0 example:1 2 3 4 5

②首或者尾排好----ans=1 example:1 3 2 4 5、1 5 2 3 4

③首尾都没排好有两种情况:

①:恰好首在尾,尾在首:5 2 3 4 1----ans=3

②:其他情况: 2 3 4 1 5 ----ans=2

#include<bits/stdc++.h>
using namespace std;
const int maxn=55;
int a[maxn];
int main()
{
    int n,i,j,t;
    cin>>t;
    while(t--){
        cin>>n;
        int f1=0;
        for(i=0;i<n;i++){
            cin>>a[i];
            if(a[i]!=i+1) f1=1;
        }
        if(f1==0){
             cout<<0<<endl;
        }
        else {
            int d1,d2;
            for(i=0;i<n;i++){
                if(a[i]!=i+1){
                    d1=i;break;
                }
            }
            for(i=n-1;i>=0;i--){
                if(a[i]!=i+1){
                    d2=i;break;
                }
            }
            if(d1!=0||d2!=n-1){
                cout<<1<<endl;
            }
            else if(a[d1]==n&&a[d2]==1){
                cout<<3<<endl;
            }
            else {
                cout<<2<<endl;
            }
        }
    }
}


相关文章
|
6月前
Codeforces Round #192 (Div. 2) (330B) B.Road Construction
要将N个城市全部相连,刚开始以为是最小生成树的问题,其实就是一道简单的题目。 要求两个城市之间不超过两条道路,那么所有的城市应该是连在一个点上的,至于这个点就很好找了,只要找到一个没有和其他点有道路限制的即可。
18 0
|
7月前
|
机器学习/深度学习 人工智能
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
Educational Codeforces Round 113 (Rated for Div. 2)C. Jury Meeting
36 0
|
10月前
|
人工智能 测试技术
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
Codeforces Round #746 (Div. 2) C. Bakry and Partitioning
43 0
|
12月前
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
60 0
|
人工智能 Windows
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
Educational Codeforces Round 113 (Rated for Div. 2) C - Jury Meeting (思维 组合数)
72 0
|
机器学习/深度学习 Java
codeforces Educational Codeforces Round 49 (Rated for Div. 2) C题
刚开始拿到这题很懵逼,知道了别人的思路之后开始写,但是还是遇到很多坑,要求求P2/S最大。p=a b。就是求(a2+ b2 +2ab)/ab最大,也就是a/b +b/a最大。那么题意就很明显了。
87 0
|
人工智能
Educational Codeforces Round 98 (Rated for Div. 2)B-Toy Blocks
You are asked to watch your nephew who likes to play with toy blocks in a strange way. He has n boxes and the i-th box has ai blocks. His game consists of two steps: he chooses an arbitrary box i; he tries to move all blocks from the i-th box to other boxes.
236 0