题解:P17193 [KOI 2026 #2] 搭骰子塔
void_ghost · · 题解
题意比较明了,就不多赘述,直接进入正文。
题目传送门
思路
由题意可知,只有相接触的面上所写的数必须相同才能叠成塔。
我们设有两个数字(分别为两个骰子的顶面数字)为
分别的对应关系为:
知道了对应关系,还需要知道数量对于塔的贡献,于是我们设以
第一种情况:
当
第二种情况:
我们设
例如:
可见
第三种情况:
若
可见,能组成1座塔,显然对答案的贡献为
代码
喜闻乐见的代码环节
#include <bits/stdc++.h> //万能头
typedef long long ll ; //个人习惯,可去掉
using namespace std ;
const int N = 10 ; //开大3到10总不会有坏处
int n , cnt [N] ;
int ans ;
int main() {
ios::sync_with_stdio( false ) ;//流式加速
cin.tie( 0 ) ;//关闭同步
cout.tie( 0 ) ;
cin >> n ;
for ( int i = 1 ; i <= n ; i++ ) {
int x ;
cin >> x ;
cnt [x]++ ;//对应的数量加1
}
for ( int i = 1 ; i <= 3 ; i++ ) {
if ( cnt [ 7 - i ] == 0 ) {
ans += cnt [i] ;
continue ;
} //对应第一种情况
int ma = max ( cnt [i] , cnt [ 7 - i ] ) ,
mi = min ( cnt [i] , cnt [ 7 - i ] ) ;
if ( ma - mi >= 1 )
ans += ma - mi ;//对应第二种情况
else {
ans++ ;//对应第三种情况
}
}
cout << ans ;
return 0 ;//好习惯
}
完结撒花!!!