Codeforces Round #739 (Div. 3)

赛后研究了两个小时的被hack的代码,都没看懂人家怎么能hack掉的qwq



ABC直接放代码了,应该很好理解

A - Dislike of Threes

// Problem: A. Dislike of Threes
// Contest: Codeforces - Codeforces Round #739 (Div. 3)
// URL: https://codeforces.com/contest/1560/problem/A
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Edited on 2021-08-18 22:37:11

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define Endl "\n"
#define endl "\n"
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e5 + 10;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int k;
vector<int> ans;

int main(){
	for(int i = 1; i <= 100000; i++){
		if(i % 3 != 0 && i % 10 != 3){
			ans.push_back(i);
			// cout << i << endl;
		}
	}
	
	cin >> T;
	while(T--){
		cin >> k;
		cout << ans[k - 1] << endl;
	}
}

B - Who’s Opposite?

// Problem: B. Who's Opposite?
// Contest: Codeforces - Codeforces Round #739 (Div. 3)
// URL: https://codeforces.com/contest/1560/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Edited on 2021-08-18 22:37:14

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define Endl "\n"
#define endl "\n"
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e5 + 10;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
ll a, b, c;

int main(){
	cin >> T;
	while(T--){
		cin >> a >> b >> c;
		if(a < b) swap(a, b);
		
		ll summ = (a - b) * 2;
		
		if(c > summ || summ < a) cout << -1 << endl; // 与给出的最大的编号大
		else{
			if(c + summ / 2 > summ) cout << c - summ / 2 << endl;
			else cout << (c + summ / 2) << endl;
		}
	}
}

C - Infinity Table

每行第一个都是完全平方数,放一个图,代码就是根据这个图写的,先横着再竖着

代码写的有点乱,因为比赛的时候想着抓紧写完就行了,就没改

在这里插入图片描述

// Problem: C. Infinity Table
// Contest: Codeforces - Codeforces Round #739 (Div. 3)
// URL: https://codeforces.com/contest/1560/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Edited on 2021-08-18 22:37:18

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define Endl "\n"
#define endl "\n"
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e9;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
int k;
vector<ll> base;

int main(){
	ll _;
	for(ll i = 1; i * i <= N; i++){
		base.push_back(i * i);
		_ = i;
	}
	_++;
	base.push_back(_*_);
	
	
	cin >> T;
	while(T--){
		cin >> k;
		
		if(k == 1 || k == 2 || k == 3 || k == 4){
			if(k == 1) cout << "1 1" << endl;
			if(k == 2) cout << "1 2" << endl;
			if(k == 3) cout << "2 2" << endl;
			if(k == 4) cout << "2 1" << endl;
			continue;
		}
		
		ll r = lower_bound(base.begin(), base.end(), k) - base.begin() + 1;
		// cout <<r << Endl;
		
		ll flag = 0; // not found
		ll b = base[r - 1];
		if(b - (ll)sqrt(b) + 1 == k){
			b = sqrt(b);
			cout << b << " " << b << endl;
			continue;
		}
		// cout << base[r - 1] << endl;
		for(ll i = b, c = 1; i >= b - (ll)(sqrt(b)) + 2; i--, c++){
			if(i == k){
				cout << r << " " << c << endl;
				flag = 1;
				break;
			}
		}
		if(flag) continue;
		ll sb = sqrt(b);
		for(ll i = b - (ll)sqrt(b), rr = r - 1; i >= b - sb * 4 + 2; i--, rr--){
			if(i == k){
				cout << rr << " " << sb << endl;
				flag = 1;
				continue;
			}
		}
	}
}

D - Make a Power of Two

给定

// Problem: D. Make a Power of Two
// Contest: Codeforces - Codeforces Round #739 (Div. 3)
// URL: https://codeforces.com/contest/1560/problem/D
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// Code by: ING__
// 
// Edited on 2021-08-19 01:41:24

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#include <unordered_map>
#define ll long long
#define ull unsigned long long
#define re return
#define Endl "\n"
#define endl "\n"
#define x first
#define y second

using namespace std;

typedef pair<int, int> PII;

const int N = 1e5 + 10;

int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};

int T;
ll n;
string base[70];

bool check2(ll x){ // 学到了
	if(x & (x - 1) == 0) return 1;
	else return 0;
}

string tostr(ll x){
	stringstream ss;
	ss << x;
	string s;
	ss >> s;
	return s;
}

void init(){
	for(int i = 0; i < 64; i++){
		ll x = (1ll << i);
		base[i] = tostr(x);
	}
}

int cmp(string s, string s2){
	int j = 0;
	int cnt = 0;
	
	for(int i = 0; i < s.size(); i++){
		if(s[i] == s2[j]){
			j++;
			cnt++; // 匹配上了cnt个数
		}
	}
	
	return s.size() - cnt + s2.size() - cnt; // 有匹配上的就可以删s.size()-cnt个数,没匹配上的从后面再加s2.size()-cnt个数
}

int main(){
	init();
	
	cin >> T;
	while(T--){
		cin >> n;
		if(check2(n)) cout << 0 << endl;
		else{
			int ans = 0x3f3f3f3f;
			string x = tostr(n);
			for(int i = 0; i < 64; i++){
				ans = min(ans, cmp(x, base[i]));
			}
			cout << ans << Endl;
		}
	}
}

E - Polycarp and String Transformation

参考:https://www.bilibili.com/video/BV1764y1v7Us?p=4

https://blog.csdn.net/messywind/article/details/119809497

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int T;
int st[128];
int cnt[128];

int main(){
    cin >> T;
    while(T--){
        memset(st, 0, sizeof(st));
        memset(cnt, 0, sizeof(cnt));

        string str;
        cin >> str;

        string sx; // shun xu
        for (int i = str.size() - 1; i >= 0; i--){
            if(!cnt[str[i]])
                sx += str[i];
            cnt[str[i]]++;
        }

        int flag = 1;
        reverse(sx.begin(), sx.end());
        int summ = 0;

        for (int i = 0; i < sx.size(); i++){
            if(cnt[sx[i]] % (i + 1)){
                flag = 0;
                break;
            }
            summ += cnt[sx[i]] / (i + 1);
        }

        if(!flag){
            cout << -1 << endl;
            continue;
        }

        string s = str.substr(0, summ);
        // cout << s << endl;
        string t = s; // 复原
        for (int i = 0; i < sx.size(); i++){
            st[sx[i]] = 1;
            for (int j = 0; j < s.size(); j++){
                if(!st[s[j]])
                    t += s[j];
            }
            // cout << t << endl;
        }

        // cout << sx << endl;

        if(str != t)
            cout << -1 << endl;
        else
            cout << s << " " << sx << endl;
    }
}

F - Nearest Beautiful Number (hard version)

数位DP(先一放,等刷多了dp再来

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值