CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)

CodeTON Round 4 (Div. 1 + Div. 2, Rated, Prizes!)

B. Candies

在这里插入图片描述

关于b题,昨天大概是脑子被夹了,所以没想到吧,emmm
在这里插入图片描述

#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define deb2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y <<endl

using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> PII;

int a[N];

void run()
{
	int n; cin >> n;
	if(n % 2 == 0) cout << -1 << endl;
	else {
		int x= n, cnt = 0, i;
		while(x) {
			x >>= 1;
			cnt += 1;
		}
		cout << cnt - 1<< endl;
		for (i = cnt-1; i >= 1; i-- ) {
			x = n >> i;
			if(x & 1) cout <<2 << ' ';
			else cout << 1 <<' ';
		}
		cout << endl;
	}
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
    cout << fixed; cout.precision(18);
    int T = 1;
    cin >> T;
    
    while(T -- ) run();
    
}

C. Make It Permutation

在这里插入图片描述

终于不T了,因为,其实复杂度是n平方log,没想清楚
在这里插入图片描述
在这里插入图片描述
过了,真无语啊,这都能行

#include <bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i = a; i <= b; i ++ )
#define deb2(x, y) cout << #x << '=' << x << ',' << #y << '=' << y <<endl

using namespace std;

const int N = 2e5 + 10, mod = 1e9 + 7;
typedef long long ll;
typedef pair<int, int> PII;

int a[N];
set<int> st;
map<int, int> mp;
int n, c, d;


void run()
{
	st.clear();
	mp.clear();
	cin >> n >> c >> d;
	int i, j;
	for (i = 1; i <= n; i ++)  {
		cin >> a[i];
		st.insert(a[i]);
	}
	int k = 0;
	for (auto t : st){
		 mp[t] = ++k; 
	}
	sort(a + 1, a + n + 1);
	ll minx = 100000000000000000;
	int t = 0, t2 = 0;
	for (i = 1; i <= n; i ++ ) {
		int k = mp[a[i]];
		t = a[i] - k;
		t2 = (n-k);
		if(t < 0) continue;
		ll res = (ll)d*t + c*t2;
//		deb2(t, t2);
		minx = min(minx, res);
	}
	minx = min((ll)c*n+d, minx);
	cout << minx << endl;
}

signed main()
{
    ios::sync_with_stdio(false), cin.tie(0);
//    cout << fixed; cout.precision(18);
    int T = 1;
    cin >> T;
    
    while(T -- ) run();
    
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值