Educational Codeforces Round 69 (Rated for Div. 2)

A. DIY Wooden Ladder

题意:搭梯子,选两条最长的边为基础边,然后选择其他边当台阶,并且台阶数小于基础边;

#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int main()
{
        ios::sync_with_stdio(false);
        int T;
        cin>>T;
        while(T--){
                int n;
                cin>>n;
                int a[maxn];
                for(int i=0;i<n;i++){
                        cin>>a[i];
                }
                sort(a,a+n);
                int flag=a[n-2]-1;
                if(n-2>=flag){
                        cout<<flag<<endl;
                }
                else cout<<n-2<<endl;
        }
        return 0;
}

B. Pillars

题意:n个位置,每个位置一个半径为ai的碟子,移动碟子,判断能否全部叠在一起,移动的条件满足:位置i->j,abs(i-j)==1,i要有碟子,j要么没有,要么就半径要大于i;

思路:记录最大半径的位置,最大半径的位置一定不会移动,然后向两边找比最大半径小的,(特殊是半径不会相同,并且是1-n)

#include <bits/stdc++.h>
using namespace std;
const int maxn=2e5+100;
int main()
{
        ios::sync_with_stdio(false);
        int a[maxn];
        int n;
        cin>>n;
        int flag;
        for(int i=1;i<=n;i++){
                cin>>a[i];
                if(a[i]==n){
                        flag=i;
                }
        }
        int cnt=n-1,l=flag-1,r=flag+1;
        while(cnt>0){
                if(l>0&&a[l]==cnt)
                {
                        l--;
                        cnt--;
                }
                else if(r<=n&&a[r]==cnt)
                {
                        r++;
                        cnt--;
                }
                else
                {
                        cnt=-2;
                        break;
                }
                //cout<<"l="<<l<<"r="<<r<<"cnt"<<cnt<<endl;
        }
        if(cnt==-2)
                cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
        return 0;
}

C. Array Splitting

题意:给n个数,并且已经按递增排序,要分成k个子集,计算所有子集最大值和最小值的差和,使得这个和最小;

思路:当子集为1个数的时候,这个的差为0,所以在n个数分成k份时,k-1个为1个数的子集时,n-k个不为1个数的子集时最小,计算数组中两两差值,排序,答案就是前n-k个最小值和;

#include <bits/stdc++.h>
using namespace std;
const int maxn=3e5+100;
int main()
{
        ios::sync_with_stdio(false);
        int a[maxn];
        int n,k;
        cin>>n>>k;
        for(int i=1;i<=n;i++){
                cin>>a[i];
        }
        int b[maxn];
        for(int i=1;i<n;i++){
                b[i]=a[i+1]-a[i];
        }
        sort(b+1,b+n);
        int sum=0;
        for(int i=1;i<=n-k;i++)
        {
                sum+=b[i];
        }
        cout<<sum<<endl;
}

原文地址:https://www.cnblogs.com/lin1874/p/11229539.html

时间: 2024-08-30 01:29:13

Educational Codeforces Round 69 (Rated for Div. 2)的相关文章

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code

Educational Codeforces Round 69 (Rated for Div. 2) E. Culture Code 题目链接 题意: 给出\(n\)个俄罗斯套娃,每个套娃都有一个\(in_i,out_i\),并满足\(out_i>in_i\).定义套娃\(i\)能套在套娃\(j\)里面,当且仅当\(out_i\leq in_j\). 定义极大套娃组:当且仅当不能有另外一个套娃套在它们身上. 定义套娃组额外空间为\(in_1+(in_2-out_1)+\cdots +(in_k-

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w

Educational Codeforces Round 55 (Rated for Div. 2)

Educational Codeforces Round 55 (Rated for Div. 2) 链接 A Vasya and Book 傻逼题..注意判边界. #include<cstdio> #include<cstring> #include<algorithm> #include<queue> #include<set> #include<map> #include<vector> #include<cm

Educational Codeforces Round 57 (Rated for Div. 2)

get人生第二场CF! 成绩:(exACM) rank858 AC3/7 Penalty57 rating1648(+52) 题目:Educational Codeforces Round 57 (Rated for Div. 2) 错题题解: D. Easy Problem E. The Top Scorer F. Inversion Expectation G. Lucky Tickets 原文地址:https://www.cnblogs.com/xht37/p/10198321.html

Educational Codeforces Round 58 (Rated for Div. 2)(待更新)

get人生第七场CF! 成绩:(exACM) rank AC3/7 Penalty104 rating() 题目:Educational Codeforces Round 58 (Rated for Div. 2) 错题题解: C. Division and Union 原文地址:https://www.cnblogs.com/xht37/p/10260260.html