Codeforces Round #677(Div.3)


Codeforces Round #677 传送门


A. Boring Apartments

题意:
有一栋公寓有编号为1~10000的房间,从1开始拨打电话到n为止,求拨号到所有每位数字相同(例如“11”“9999”)的房间按下的次数和。例如,如果n==22,那么拨号为1、11、111、1111、2、22,按下的数字总数是1+2 +3+4+1+2=13。

思路:
水题,模拟即可

AC代码:

#include<iostream>
using namespace std;
int main(){
	int n;
	cin >> n;
	while(n--){
		int boring,sum,k;
		sum = k = 0;
		cin >> boring;
		k = boring % 10;
		sum = 10*(k-1);
		for(int i=1;boring>0;i++){
			boring /= 10;
			sum += i;
		}
		cout << sum << endl;
	}
	
	return 0;
} 

B. Yet Another Bookshelf

题意:
一排书架,0表示没书1表示有书,可以将连续的书或一本书向任意方向移动一格,但不能移出书架,求将所有书移动至连续的最少移动次数。

思路:
向聚集方向移动,每次移动会使1覆盖一个0。所以找到首尾的“1”,计算中间“0”的数量即移动次数。

AC代码:

#include<bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	while(t--){
		int a[52]={0};
		int n,min=99,max=0,k=0;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> a[i];
			if(a[i]==1&&min==99){
				min = i;
			}
		}
		for(int i=n-1;i>0;i--){
			if(a[i]==1&&max==0){
				max = i;
			}
		}
		for(int i=min;i<max;i++){
			if(a[i]==0){
				k++;
			}
		}
		cout << k << endl;
	}
}

C. Dominant Piranha

题意:
给定一列数字,其中数字可以吃掉左右比他小的数并使自身+1,问是这个数的位置

思路:
找到最大的数,并判断它的左右是否均为最大的数,使左右存在小于它的数。如果所有数相等则不存在此数。

AC代码:

#include<bits/stdc++.h>
using namespace std;
long long fish[300006];
int main(){
	int t;
	cin >> t;
	while(t--){
		int n,jud=1,num,max;
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> fish[i];
		}
		for(int i=1;i<n;i++){
			if(fish[i]!=fish[i-1]){
				jud = 0;
				break;
			}
		}
		if(jud==1){
			cout << -1 << endl;
			continue;
		}
		else{
			max = fish[0];
			for(int i=0;i<n;i++){
				if(max<fish[i]){
					max = fish[i];
				} 
			}
			for(int i=0;i<n;i++){
				if(i==0){
					if(fish[i]==max && fish[i+1]<fish[i]){
						num = i+1;
						break;
					}
				}
				else if(i==n-1){
					if(fish[i]==max && fish[i-1]<fish[i]){
						num = i+1;
						break;
					}
				}
				else{
					if(fish[i]==max && (fish[i-1]<fish[i] || fish[i+1]<fish[i])){
						num = i+1;
						break;
					}
				}
				
			}
			cout << num << endl;
		}
		
	}
	return 0;
}

D. Districts Connection

题意:
给定n个数字,将数字连接成一个通路,相同的数字不能相邻,可以则输出“YES”和(n-1)个相邻数,否则输出“NO”。

思路:
暴力即可,从头到尾循环一遍,不一样的直接输出,一样的再小循环一下找个不同的,全相同输出NO。

AC代码:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int t;
	cin >> t;
	while(t--){
		int n,same=1;
		ll a[5006];
		cin >> n;
		for(int i=0;i<n;i++){
			cin >> a[i];
			if(i>0 && a[i]!=a[i-1]){
				same = 0;
			}
		}
		if(same == 1){
			cout << "NO" << endl;
			continue;
		}
		else{
			cout << "YES"<< endl;
			for(int i=1;i<n;i++){
				if(a[0]!=a[i]){
					cout << 1 <<" "<< i+1 <<endl;
				}
				else{
					for(int j=0;j<n;j++){
						if(a[i]!=a[j]){
							cout << j+1 <<" "<< i+1 <<endl;
							break;
						}
					}
				}
			}
		}	
		
	}
	return 0;
} 

ps:蒟蒻首发,哪有问题望大佬指正

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值