A
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation ll pre[200005]; int main() { //freopen("out.txt","w",stdout); int n; cin >> n; ll sum = 0; ll now; for (int i = 1; i <= n; i++) { cin >> now; pre[i] = pre[i - 1] + now; sum += now; } for (int i = 1; i <= n; i++) { if (pre[i]*2>= sum) { cout << i << endl; return 0; } } }
B
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation int kuai[200005]; int pop = 0; int main() { //freopen("out.txt","w",stdout); int n, a, b; cin >> n >> a >> b; string s; cin >> s; int len = s.size(); int cur = 0; for (int i = 0; i <= n; i++) { if (i == n || s[i] == ‘*‘) { kuai[++pop] = cur; cur = 0; continue; } if (s[i] == ‘.‘) { cur++; } } int anser = 0; int jian; for (int i = 1; i <= pop; i++) { if (kuai[i] == 0) { continue; } //cout << kuai[i] << " "; if (kuai[i] % 2 == 0) { anser += min(a, kuai[i] / 2) + min(b, kuai[i] / 2); a -= min(a, kuai[i] / 2); b -= min(b, kuai[i] / 2); } else { anser += min(a, kuai[i] / 2) + min(b, kuai[i] / 2); a -= min(a, kuai[i] / 2); b -= min(b, kuai[i] / 2); if (a >= b && a > 0) { anser++; a--; continue; } if (b >= a && b > 0) { anser++; b--; continue; } } } cout << anser << endl; }
C
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation ll n; ll lenn = 0; ll len = 0; ll sqr[100005]; int pop = 0; ll anser = 100; int aim[11]; int num[11]; int dfs(int x, int str) { if (x == 0) { return 1; } if (str == 0 && x != 0) { return 0; } if (x % 10 == str % 10) { return dfs(x / 10, str / 10); } else { return dfs(x, str / 10); } } int main() { //freopen("out.txt","w",stdout); cin >> n; for (ll i = 1; i <= 100000; i++) { if (1LL * i * i > 2000000000) { break; } else { sqr[i] = 1LL * i * i; pop++; } } ll cur = n; ll now = 0; int flag; while (cur > 0) { num[cur % 10]++; cur /= 10; lenn++; } for (int i = 1; i <= pop; i++) { mem(aim, 0); cur = sqr[i]; flag = dfs(cur, n); if (flag) { len = 0; cur = sqr[i]; while (cur > 0) { cur /= 10; len++; } anser = min(lenn - len,anser); } } if (anser == 100) { cout << -1 << endl; } else { cout << anser << endl; } }
D
#include <bits/stdc++.h> #define PI acos(-1.0) #define mem(a,b) memset((a),b,sizeof(a)) #define TS printf("!!!\n") #define pb push_back #define inf 0x3f3f3f3f //std::ios::sync_with_stdio(false); using namespace std; //priority_queue<int,vector<int>,greater<int>> que; get min const double eps = 1.0e-10; const double EPS = 1.0e-4; typedef pair<int, int> pairint; typedef long long ll; typedef unsigned long long ull; //const int maxn = 3e5 + 10; const int turn[4][2] = {{0, 1}, { 1, 0}, { 0, -1}, { -1, 0}}; //priority_queue<int, vector<int>, less<int>> que; //next_permutation ll num[150005]; int visit[150005]; int anser = 0; pair<ll, ll> cur, cnt, now; priority_queue<pair<ll, ll>, vector<pair<ll, ll> >, greater<pair<ll, ll> > > que; int main() { //freopen("out.txt","w",stdout); ll n; cin >> n; for (int i = 1; i <= n; i++) { scanf("%lld", &num[i]); } for (int i = 1; i <= n; i++) { cur.first = num[i], cur.second = i; que.push(cur); } while (!que.empty()) { cur = que.top(); que.pop(); if (que.top().first > cur.first || !que.size()) { visit[cur.second] = 1; num[cur.second] = cur.first; continue; } cnt = que.top(); que.pop(); num[cnt.second] = cur.first + cnt.first; now.first = cur.first + cnt.first, now.second = cnt.second; que.push(now); } for (int i = 1; i <= n; i++) { if (visit[i]) { anser++; } } cout << anser << endl; for (int i = 1; i <= n; i++) { if (visit[i]) { cout << num[i] << " "; } } cout << endl; }
原文地址:https://www.cnblogs.com/Aragaki/p/8799334.html
时间: 2024-10-08 04:52:35