首页 > 其他分享 >One Bamboo Contest Round #12(Clone from 2020 ICPC Shenyang)

One Bamboo Contest Round #12(Clone from 2020 ICPC Shenyang)

时间:2023-01-08 15:25:24浏览次数:56  
标签:12 Contest int res Clone long read ch ans

G. The Witchwood

签到

#include <bits/stdc++.h>
#define int long long
using namespace std;

int read(){
    int x = 0 , ch = getchar();
    while( ch < '0' || ch > '9' ) ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = x * 10 + ch - '0' , ch = getchar();
    return x;
}


int32_t main(){
    int n = read() , m = read();
    vector<int> a(n);
    for( auto & i : a ) i = read();
    std::sort(a.begin(), a.end(),greater<int>());
    int res = 0;
    for( int i = 0 ; i < m ; i ++ )
        res += a[i];
    cout << res << "\n";
    return 0;
}

F. Kobolds and Catacombs

题目的意思是,把序列尽可能的划分成多个子区间,要求对子区间排序后整个序列有序。

首先设第\(j\)个区间为\([l_j,r_j]\),由此可知\(l_1=1,l_j = r_{j-1}+1\),并且每个区间应该满足\([l_j,r_j]\)中的最大值小于\([r_j+1,n]\)中的最小值。

所以先计算出后缀最小值,然后根据后缀最小值就能找到每个右端点的位置。

#include <bits/stdc++.h>
#define int long long
using namespace std;

int read(){...}

int32_t main(){
    int n = read()  , cnt = 0;
    vector<int> v(n) , b(n);
    for( auto & i : v ) i = read();
    b[n-1] = v[n-1];
    for( int i = n - 2 ; i >= 0 ; i -- ) b[i] = min( v[i] , b[i+1] );
    b.push_back(INT_MAX) , v.push_back(INT_MIN) ;
    int l = 0;
    for( int i = 0 ; i < n && l < n ; i ++ ){
        if( v[i] > v[l] ) l = i;
        if( b[i+1] >= v[l] ) cnt ++ , l = i+1;
    }
    cout << cnt << "\n";
    return 0;
}

K. Scholomance Academy(补题)

这道题感觉蛮难理解的,最主要的就是那个AUC的积分,其实要求的就是就是样例解释里面阴影部分的面积。

因为数据是离散的,所以可以直接枚举排序后的\(a_i\)作为\(\theta\)的值,如果是阳性TP--,如果是阴性就要统计答案。

至于题目中定义的几个概念是机器学习中的东西,可以参考这篇博客

#include <bits/stdc++.h>
#define int long long
using namespace std;

struct Node{
    bool c;
    int s;
    Node( bool c = false , int s = 0 ) : c(c) , s(s){};
    bool operator < ( Node b ) const {
        if( s == b.s ){
            if(b.c) return false;
            if(c) return true;
        }
        return s < b.s;
    }
};


int32_t main(){
    int n , positive = 0 , negative = 0;
    cin >> n;
    vector<Node> a(n+1);
    for( int i = 1 ; i <= n ; i ++ ){
        char c;
        cin >> c >> a[i].s;
        a[i].c = (c == '+');
        if( a[i].c ) positive ++;
        else negative ++;
    }
    sort( a.begin()+1 , a.end());
    long double res = 0 , tp = positive , cnt = positive * negative;
    for( int i = 1 ; i <= n ; i ++ ){
        if( a[i].c ) tp --;
        else res += tp;
    }
    cout << fixed << setprecision(9) << res / cnt;
   return 0;
}

D. Journey to Un'Goro(补题)

令\(p_i\)表示前\(i\)中有多少个\(r\),则题目要求对于区间\([l,r]\)满足\(p_r-p_{l-1}\)为奇数的区间尽可能的多。

那么则\(p_i\)为奇数的个数和为偶数的个数越接近越多,最多的情况就是各一半。注意的是\(i\)的取值是\([0,n]\)共\(n+1\)个。

那么用搜索枚举出前100种情况就好,剪枝如果过程种\(p_i\)为奇数(或为偶数)的个数大于一半就一定不行

#include <bits/stdc++.h>
#define int long long
using namespace std;

int read(){
    int x = 0 , f = 1 , ch = getchar();
    while( (ch < '0' || ch > '9') && ch != '-' ) ch = getchar();
    if( ch == '-' ) f = -1 , ch = getchar();
    while( ch >= '0' && ch <= '9' ) x = ( x << 3 ) + ( x << 1 ) + ch - '0' , ch = getchar();
    return x * f;
}

vector<char> s;
int cnt = 0 , n , res , ans;

void dfs( int i , int cntEven , int cntOdd , int p ){
    if( cntEven > ans || cntOdd > ans ) return;
    if( i == n ){
        if( abs( cntOdd - cntEven) <= 1 ){
            for( auto c : s ) printf("%c",c);
            printf("\n");
            if( ++ cnt == 100 ) exit(0);
        }
        return;
    }
    s[i] = 'b';
    dfs( i+1 , cntEven + (p==0) , cntOdd + (p==1) , p );
    s[i] = 'r';
    dfs( i+1 , cntEven + (p==1) , cntOdd + (p==0) , p^1 );
    return;
}

int32_t main(){

    cin >> n;
    s = vector<char>(n);
    ans = (n+2) / 2 , res = ans * ( n+1-ans );
    cout << res << "\n";
    dfs( 0 , 1 , 0 , 0 );
    return 0;
}

标签:12,Contest,int,res,Clone,long,read,ch,ans
From: https://www.cnblogs.com/PHarr/p/17034700.html

相关文章

  • One Bamboo Contest Round #10
    A.CowardlyRooks在\(n\timesn\)的棋盘中有m个车,问是否可以在移动任意一个棋子一步后是的m个车不能相互攻击如果m>n无论如何都会冲突首先要统计冲突的数量如果没有......
  • One Bamboo Contest Round #11(Clone from 2022 ICPC Manila)
    马尼拉区域赛题目出得还是不错的,只是感觉大多数参赛队伍的水平不太行,我们这样的队伍居然能苟到铜牌A.AnEasyCalculusProblem签到#include<bits/stdc++.h>#define......
  • AtCoder Beginner Contest 284-F - ABCBAC(双哈希)
    F-ABCBAC题目大意:给定一个正整数n,和一个长度为2*n的字符串s问s串能不能是由一个t串经过如下操作变成s串:t串的前i个字符t串的反转串t串的后(n-i)个字符如果存在......
  • 新概念第一册111~120单元学习笔记
    Chapterhundredandeleven:ThemostexpensivemodelDialogue标题用到more的用法more/themost+adj.#多音节(>=2)形容词,前加more,most表更多less/theleast+adj.#少......
  • 2023.1.7(Atcoder Beginner Contest 284)
    A.HappyNewYear2023Linkhttps://atcoder.jp/contests/abc284/tasks/abc284_dStatement将给定的\(N\)分解成\(N=p^2\cdotq\)的形式,其中\(p,q\)为两个不......
  • Atcoder Beginner Contest ABC 284 Ex Count Unlabeled Graphs 题解 (Polya定理)
    题目链接弱化版(其实完全一样)u1s1,洛谷上这题的第一个题解写得很不错,可以参考直接边讲Polya定理边做这题问题引入:n颗珠子组成的手串,每颗珠子有两种不同的颜色,如果两......
  • 【2022-12-28】连岳摘抄
    23:59中国人已经进入长寿社会,百岁老人比比皆是,而且比例将越来越高。很多人退休之时,人生刚走完一半。后面这半生如何安排,就显得非常重要。退休后不做点事,闲得发慌,既是巨大......
  • 【2022-12-29】看见自己
    20:00爱一个人时,我们总希望他们快乐;他们不快乐,你也不会快乐。但快乐并不是一个人的事,真爱应能相互理解。爱,实际上是“理解”的别称。如你无法理解他人,也就无法正确地去爱......
  • Atcoder Beginner Contest ABC 284 Ex Count Unlabeled Graphs 题解 (Polya定理)
    题目链接弱化版(其实完全一样)u1s1,洛谷上这题的第一个题解写得很不错,可以参考直接边讲Polya定理边做这题问题引入:n颗珠子组成的手串,每颗珠子有两种不同的颜色,如果两......
  • Atcoder Beginner Contest 284总结
    前言第一次做出6道题。比赛过程A题白给,耗时\(\text{1min}\)。B题白给,然而突然忘了oddnumber是奇数还是偶数,于是翻译了一下。耗时\(\text{2mins}\)。C题直接......