2022年5月18日刷题

12 篇文章 0 订阅
12 篇文章 1 订阅

继续Brush,brush,brush.

友情提醒:

找到CodeForces最近的5场比赛:
比赛名称:Codeforces Round #792 (Div. 1 + Div. 2)
比赛时间:2022-05-19 22:35:00
比赛链接:https://codeforces.com/contest/1684
比赛名称:Codeforces Round #793 (Div. 2)
比赛时间:2022-05-22 22:35:00
比赛链接:https://codeforces.com/contest/1682
比赛名称:Educational Codeforces Round 129 (Rated for Div. 2)
比赛时间:2022-05-23 22:35:00
比赛链接:https://codeforces.com/contest/1681
比赛名称:Codeforces Round #794 (Div. 2)
比赛时间:2022-05-26 01:35:00
比赛链接:https://codeforces.com/contest/1686
比赛名称:Codeforces Round #794 (Div. 1)
比赛时间:2022-05-26 01:35:00
比赛链接:https://codeforces.com/contest/1685

目录

A - Tokitsukaze and All Zero Sequence


A - Tokitsukaze and All Zero Sequence

点击打开题目

题目大意:

Tokitsukaze有一个长度为n的序列a。对于每个操作,她选择两个数字ai和aj(i≠j; 1≤i,j≤n) 。如果ai=aj,将其中一个更改为0。否则,将两者都更改为min(ai,aj)。Tokitsukaze想知道将序列中的所有数字更改为0的最小操作数。可以证明,答案总是存在的。

题目思路:不硬做,思维题。

AC代码:

#include<bits/stdc++.h>
using namespace std;
#define AC return 0;
#define geta(n,m); for(int i=n;i<m;i++){cin>>a[i];}
void solve(){
	int n; cin>>n;
	vector<int>a(n+2);
	vector<int>b(112);
	geta(0,n);
	for(int i=0;i<110;i++) b[i]=0;
	for(int i=0;i<n;i++) b[a[i]]++;
	if(b[0]){
		cout<<n-b[0]<<endl;
		return;
	}
	for(int i=0;i<110;i++){
		if(b[i]>=2){
			cout<<n<<endl;
			return;
		} 
	}
	cout<<n+1<<endl;
	return;
}
int main(){
    cin.tie(0);
	ios::sync_with_stdio(0);
	int tc; cin>>tc;
	while(tc--) solve(); 
	AC
}
//ACplease!!!


/*  printf("                                                                \n");
	printf("                                                                \n");
	printf("       * * *               * * *             * * *             * * *            \n");
	printf("     *       *           *       *         *      *          *       *         \n");
	printf("    *        *          *         *       *        *        *         *        \n");
	printf("            *           *         *                *                  *      \n");
	printf("           *            *         *               *                  *     \n");
	printf("          *             *         *              *                  *       \n");
	printf("         *              *         *             *                  *            \n");
	printf("        *               *         *           *                  *            \n");
	printf("      *                  *       *          *                  *           \n");
	printf("    * * * * * * *          * * *          * * * * * * *      * * * * * * *                           \n");
*/    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值