码迷,mamicode.com
首页 > 其他好文 > 详细

CF 962(耻辱场) /2错误 相间排位 堆模拟 X轴距离最小值

时间:2018-04-12 00:12:04      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:最小值   visit   empty   isp   eof   amp   AC   ems   scanf   

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;
                }
        }
}
View Code

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;
}
View Code

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;
        }
}
View Code

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;
}
View Code

 

CF 962(耻辱场) /2错误 相间排位 堆模拟 X轴距离最小值

标签:最小值   visit   empty   isp   eof   amp   AC   ems   scanf   

原文地址:https://www.cnblogs.com/Aragaki/p/8799334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!