C. Lose it!(思維)Codeforces Round #565 (Div. 3)
原題連結: https://codeforces.com/contest/1176/problem/C
測試樣例
input
5
4 8 15 16 23
output
5
input
12
4 8 4 15 16 8 23 15 16 42 23 42
output
0
input
15
4 8 4 8 15 16 8 16 23 15 16 4 42 23 42
output
3
題意: 給你一個長度為
n
n
n的陣列,其中的元素只由
4
,
8
,
15
,
16
,
23
,
42
4,8,15,16,23,42
4,8,15,16,23,42組成。問你至少需要移除多少元素才能使得這個陣列變為好陣列。
好陣列的標準為:其陣列長度
k
k
k必須要是
6
6
6的倍數且有
k
6
\frac{k}{6}
6k個子序列:
4
,
8
,
15
,
16
,
23
,
42.
4,8,15,16,23,42.
4,8,15,16,23,42.
解題思路: 模擬操作即可,要知道起決定性因素的一定是子序列個數,因為陣列長度已經被子序列個數確定了,不用管。我們模擬的過程中一定要記住前面的元素是否存在,如果不存在這個子序列也就不存在。模擬操作具體看AC程式碼。
AC程式碼
/*
*郵箱:unique_powerhouse@qq.com
*blog:https://me.csdn.net/hzf0701
*注:文章若有任何問題請私信我或評論區留言,謝謝支援。
*
*/
#include<bits/stdc++.h> //POJ不支援
#define rep(i,a,n) for (int i=a;i<=n;i++)//i為迴圈變數,a為初始值,n為界限值,遞增
#define per(i,a,n) for (int i=a;i>=n;i--)//i為迴圈變數, a為初始值,n為界限值,遞減。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair
using namespace std;
const int inf = 0x3f3f3f3f;//無窮大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割線,以上為自定義程式碼模板***************************************//
int t,n;
int main(){
//freopen("in.txt", "r", stdin);//提交的時候要註釋掉
IOS;
while(cin>>t){
while(t--){
cin>>n;
int cnt=0;
while(n%3==0||n%5==0){
if(n%3==0){
n
cnt++;
}
if(n%5==0){
n/=5;
cnt++;
}
}
}
}
return 0;
}
相關文章
- C. Dominant Piranha(思維) Codeforces Round #677 (Div. 3)NaN
- Codeforces Round #688 (Div. 2) C. Triangles(思維,數學)
- acm-(思維、奇偶性、矩陣)Codeforces Round #682 (Div. 2) C. Engineer ArtemACM矩陣
- Codeforces Round #446 (Div. 2) C. PrideIDE
- Codeforces Round #242 (Div. 2) C. Magic FormulasORM
- Codeforces Round #215 (Div. 2) C. Sereja and AlgorithmGo
- Codeforces Round #243 (Div. 2) C. Sereja and Swaps
- Codeforces Round #646 (Div. 2)【C. Game On Leaves 題解】GAM
- Codeforces Round #228 (Div. 1) C. Fox and Card GameGAM
- Codeforces Round #251 (Div. 2) C. Devu and Partitioning of the Arraydev
- Codeforces Round #690 (Div. 3)
- Codeforces Round 954 (Div. 3)
- Codeforces Round 943 (Div. 3)
- Codeforces Round 974 (Div. 3)
- Codeforces Round 981 (Div. 3)
- Codeforces Round 962(Div. 3)
- Codeforces Round 962 (Div. 3)
- Codeforces Round 957 (Div. 3)
- Codeforces Round 950 (Div. 3)
- Codeforces Round 966 (Div. 3)
- Codeforces Round 946 (Div. 3)
- 【CodeForces】 Codeforces Round #672 (Div. 2) B.Rock and Lever (思維&位運算)
- Codeforces Round 944 (Div. 4) G(思維 + 位運算性質)
- Codeforces C. Colored Rooks 構造 (Codeforces Round #518 (Div. 2) )
- Codeforces Round #407 (Div. 1) C. The Great Mixing(bfs)
- Codeforces Round 970 (Div. 3)A~F
- Codeforces Round 981 (Div. 3)(A~E)
- Codeforces Round 933 (Div. 3)
- Codeforces Round 938 (Div. 3) E
- Codeforces Round 916 (Div. 3)
- Codeforces Round 966 (Div. 3) VP
- Codeforces Round #373 (Div. 1) C. Sasha and Array 線段樹
- Codeforces Round #713 (Div. 3)AB題
- Codeforces Round 984 (Div. 3) 題解
- Codeforces Round 962 (Div. 3) 題解
- Codeforces Round 946 (Div. 3) 題解
- Codeforces Round 970 (Div. 3) ABCDEFGH
- Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水題