Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

A.

签到题:思路为:所求答案 = 9 * (字符长度 - 1) + 最高位数 +(- 1)//通过判断语言确定是否需要再减个一 如果a****** > *******则需要加一反之不需要

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;

    int main () {
    	ll t;
    	cin >> t;
    	while(t--) {
    		ll ans;
    		ll temp = 0;
    		string num;
    		cin >> num;
    		ans = 9*(num.size() - 1) + num[0] - ‘0‘;
    		for (int i = 1; i < num.size(); ++i) {
    			if(num[i] < num[i - 1]) {
    				temp = 1;
    			}
    			if(num[i] > num[i - 1]) {
    				break;
    			}
    		}
    		ans -= temp;
    		cout << ans << endl;
    	}
    }

B

思路一:用vector去重(错误)被T成狗

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    std::vector<char> v;
    int main () {

    	ll t;
    	cin >> t;
    	while(t--) {
    		int num;
    		ll temp = 0;
    		std::vector<ll> a;
    		cin >> num;
    		for (int i = 0; i < num; i++) {
    			cin >> temp;
    			if(!(temp & 1))
    				a.push_back(temp);
    		}
    		ll ans = 0;
    		sort(a.begin(), a.end());
    		a.erase(unique(a.begin(), a.end()), a.end());

    		while(a.size()) {
    			a[a.size()-1] >>= 1;
    			//cout << "!" <<a[a.size()-1] << endl;
    			if(a[a.size()-1] & 1) {
    				a.erase(a.begin() + a.size() - 1);
    			}
    			ans++;
    			sort(a.begin(), a.end());
    			a.erase(unique(a.begin(), a.end()), a.end());

    		}
    		cout << ans << endl;
    	}
    }

正确思路:用队列进行处理,先筛出偶数进行处理,每次从大值除2进行是最快的,为奇数时剔除。每次操作进行去重。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main () {
	priority_queue <ll> q;
	ll t;
	cin >> t;
	while(t--) {
		ll num;
		cin >> num;
		for(int i = 0; i < num; ++i) {
			ll temp;
			cin >> temp;
			if(!(temp & 1)) {
				q.push(temp);
			}
		}
		ll ans = 0;
		ll temp; ll cur;
		if(!q.empty()) {
			ans++;
			temp = q.top();
			q.pop();
			if(!((temp / 2) & 1)){
				q.push(temp / 2);
			}
		}

		while(!q.empty()) {

			cur = q.top();
			q.pop();
			if(cur == temp){
				continue;
			}
			else {
				// cout << "ans:" << ans << endl;
				// cout << "cur:" << cur << endl;
				temp = cur;
				ans++;
				if(!((temp / 2) & 1)){
					q.push(temp / 2);
				}
			}
		}
		cout << ans << endl;
	}
}

未完待续。。。

原文地址:https://www.cnblogs.com/lightac/p/12041583.html

时间: 2024-10-09 07:09:23

Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)的相关文章

【cf比赛记录】Codeforces Round #606 (Div. 2, based on Technocup 2020 Elimination Round 4)

比赛传送门 只能说当晚状态不佳吧,有点头疼感冒的症状.也跟脑子没转过来有关系,A题最后一步爆搜没能立即想出来,B题搜索没有用好STL,C题也因为前面两题弄崩了心态,最后,果然掉分了. A:简单数学 B:数学+排序 C:字符串搜索 A // https://codeforces.com/contest/1277/problem/A /* 题意: 给出一个数,求不大于该数的完美整数的个数(完美整数指全是一个数组成的数字,如:111, 333333, 444444, 9, 8888 ...) 分析:

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3

A,有多个线段,求一条最短的线段长度,能过覆盖到所又线段,例如(2,4)和(5,6) 那么我们需要4 5连起来,长度为1,例如(2,10)(3,11),用(3,10) 思路:我们想一下如果题目说的是最长我们肯定是取最小x和最大的y连起来就完事. 但是要求长度最小又得覆盖,那么可以这样想,我们需要把最小的x不断右移到这条线段的y, 最大的左移到x,所以就是最大x-最小y完事 #include <bits/stdc++.h> using namespace std; #define ll long

Codeforces Round #591 (Div. 2, based on Technocup 2020 Elimination Round 1) 题解

A..B略 C 对当前的值排序,再二分答案,然后对于(i%x==0 && i%y==0)放入大的,再放其他的贪心解决即可. #include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<map> #define LL long long #define lson rt<<1 #define rson rt<

Codeforces Round #596 (Div. 2, based on Technocup 2020 Elimination Round 2)

B2 - TV Subscriptions (Hard Version) 遍历,维护一个set和set<pair<int,int>>即可 1 #include<bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 const int maxn = 1e6+7; 5 const ll mod = 1e9 + 9; 6 #define afdafafafdafaf y1; 7 int ar[maxn]

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) C. Messy 构造

C. Messy You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s1s2-sn of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation you can choo

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) B. Box 贪心

B. Box Permutation p is a sequence of integers p=[p1,p2,-,pn], consisting of n distinct (unique) positive integers between 1 and n, inclusive. For example, the following sequences are permutations: [3,4,1,2], [1], [1,2]. The following sequences are n

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) F2. Wrong Answer on test 233 (Hard Version) dp 数学

F2. Wrong Answer on test 233 (Hard Version) Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1≤n≤2?105. You can hack this problem if you locked it. But you can h

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) D2. Optimal Subsequences (Hard Version) 数据结构 贪心

D2. Optimal Subsequences (Hard Version) This is the harder version of the problem. In this version, 1≤n,m≤2?105. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a seque

Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A Math Problem

//只要从所有区间右端点的最小值覆盖到所有区间左端点的最大值即可 #include<iostream> using namespace std ; int x,y; int n; int t; int main() { cin>>t; while(t--) { cin>>n; if(n==1) { cin>>x>>y; cout<<0<<endl; } else { int l=0,r=1e9+10; for(int i=