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

1|0G. 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; }

2|0F. Kobolds and Catacombs


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

首先设第j个区间为[lj,rj],由此可知l1=1,lj=rj1+1,并且每个区间应该满足[lj,rj]中的最大值小于[rj+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; }

3|0K. Scholomance Academy(补题)


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

因为数据是离散的,所以可以直接枚举排序后的ai作为θ的值,如果是阳性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; }

4|0D. Journey to Un'Goro(补题)


pi表示前i中有多少个r,则题目要求对于区间[l,r]满足prpl1为奇数的区间尽可能的多。

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

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

#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; }

__EOF__

本文作者PHarr
本文链接https://www.cnblogs.com/PHarr/p/17034700.html
关于博主:前OIer,SMUer
版权声明CC BY-NC 4.0
声援博主:如果这篇文章对您有帮助,不妨给我点个赞
posted @   PHarr  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示