您的位置:首页 > 其它

Educational Codeforces Round 70 (Rated for Div. 2) B D

2019-08-09 18:25 357 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/qq_43676357/article/details/98972807

ORZ

#include <iostream>
#include <string>
#include <algorithm>
#define llint long long
#define inf 1000000000000000000

using namespace std;

string s;
llint cnt[15];
llint cost[15];

int main(void)
{
ios::sync_with_stdio(0);
cin.tie(0);

cin >> s;
for (int i = 1; i < s.size(); i++) {
int a = s[i] - '0', b = s[i - 1] - '0';
cnt[(a - b + 10) % 10]++;
}

for (int x = 0; x < 10; x++) {
for (int y = 0; y < 10; y++) {
for (int g = 0; g < 10; g++) {
llint mn = inf;
for (llint i = 0; i <= 10; i++) {
for (llint j = 0; j <= 10; j++) {
if (i + j == 0) continue;
if ((i*x + j * y) % 10 == g) mn = min(mn, i + j);
}
}
cost[g] = mn - 1;
}
llint ans = 0;
for (int g = 0; g < 10; g++) {
if (cnt[g] > 0 && cost[g] > inf / 2) {
ans = -1;
break;
}
ans += cnt[g] * cost[g];
}
cout << ans << " ";
}
cout << endl;
}

return 0;
}

D 题

这题其实不难

#include <bits/stdc++.h>
using namespace std;
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = 1e9 + 7;
const int N = 1e6 + 555;
const long double PI = acos(-1.0);

void solve()
{
int n;
cin >> n;
int res = 1;
while(res * (res + 1) / 2 <= n) res++;
n -= res * (res - 1)/ 2;

string ans = "133";
for(int i = 0; i < n; ++i) ans += '7';
for(int i = 0; i < res - 2; ++i) ans += '3';
ans += '7';
cout << ans << endl;

}

int main()
{
Red;
int T;
cin >> T;
while(T--)
solve();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: