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

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-07-30 13:05:18

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

【打CF,学算法——三星级】Codeforces 704A Thor (模拟)

[CF简介] 题目链接:CF 704A 题面: A. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this ph

SharePoint 2013实例1&mdash;构建三层服务器场5&mdash;配置DB层3&mdash;模拟存储

前两节我们进行DB层的配置,共享存储一般是基于硬件存储设备上的.但我们实验环境怎么来模拟群集用的存储呢?windows2012已经很好的支持了iSCSI服务,并内置入了文件服务中. 1.我们打开服务器添加角色和功能向导,打开文件和iSCSI服务,勾选iSCSI目标服务器安装此服务器角色. 安装完毕后在服务器管理器中发现多了一项:文件盒存储服务 这里我新挂载了一个硬盘作为存储用,所以首先要建立新卷. 打开卷,点开任务栏,选择新建卷. 选取新挂载的磁盘 指定卷大小,因为我这里建立的是基本磁盘,所以只

hdu 5308 (2015多校第二场第9题)脑洞模拟题,无语

题目链接:http://acm.hdu.edu.cn/listproblem.php?vol=44 题意:给你n个n,如果能在n-1次运算之后(加减乘除)结果为24的输出n-1次运算的过程,如果不能输出-1. 思路:乍看起来,没什么规律,但是可以想象的是(n+n+n+n)/n=4,(n+n+n+n+n+n)/n=6,(n-n)*n*n*·····*n=0所以在n大于15的时候结果基本是固定的,只要对小于15的数一一输出就行(但是这题真是无语,算这种题目真是累,脑洞啊~~) 代码: 1 #incl

2017多校第9场 HDU 6166 Senior Pan 堆优化Dij

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6166 题意:给你一个有向图,然后给你k个点,求其中一个点到另一个点的距离的最小值. 解法:枚举二进制位按照标号当前位为1 和当前位为0分为两个集合,每次求解两个集合之间的最短路即可覆盖到所有的点对.时间复杂度20*dijstla时间,这样做的正确性在哪?显然我们需要的答案至少有一个二进制位不同,那么这样求解肯定可以找到正确答案,事实上还可以随机分组emmmm... #include <bits/st

CF 815 A. Karen and Game(暴力,模拟)

题目链接:http://codeforces.com/problemset/problem/815/A 题目: On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains

聊聊错误注入技巧

前言 什么是"错误注入"?错误注入指的是将错误引入到我们的程序中.可能有人会很好奇,这么做有什么目的呢?答案很简单:程序的测试.因为在很多时候,当我们要进行边缘情况测试的时候,往往模拟测试的场景不是非常好造的(尤其是分布式类的程序更是如此),这个时候,我们需要有快捷的方式将错误注入到程序中,以便在我们需要发生错误时,进行错误的产生.本文笔者将结合HDFS现有的错误注入方法来介绍此部分内容. 错误注入技术的原理 错误注入技术的一个核心关键词是"拦截".正常情况下,应用

cf Round 613

A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个点距离多边形边缘最远的距离形成的圆面积减去这个点距离多边形边缘最近的距离形成的圆面积.我们可以得出距离最远的点一定是多边形的顶点.而距离最近的点不一定是多边形的顶点,但是在多边形的边上.我们用勾股定理判断点与每条边形成的三角形的两边角.如果有一个边角是钝角,则表示距离最近的点是顶点.如果都是锐角,则

mysql主从复制跳过错误项

mysql主从复制,经常会遇到错误而导致slave端复制中断,这个时候一般就需要人工干预,跳过错误才能继续 1 跳过错误有两种方式: 1.1 跳过指定数量的事务: mysql>stop slave; mysql>SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; #跳过一个事务 mysql>start slave; 1.2 修改mysql的配置文件,通过slave_skip_errors参数来跳所有错误或指定类型的错误 vi /etc/my.cnf [mysql

宝付HR带职场新人走出困惑

宝付HR带职场新人走出困惑.入职场的童鞋们有没有困惑过一些未知数,第一步要干嘛,第二步要怎么走--相关问题,我记得我刚入职场的时候曾经无数次模拟过各种情景,做梦的时候,吃饭的时候,看书的时候--尽管这些都不曾会真实的演绎,但是还会各种紧张和压迫感.人生的第一次难以决择的路程竟是依靠自己的肩膀寸步难行.明知道职场是一场持久之战,我们还可以战而不惊,无所畏惧. 宝付HR带职场新人走出困惑.任职第一天无事可做,不知道是坐着还是站着.干坐着吧,又怕被领导看到;傻站着吧,又显得傻白了些;找点事做吧,又不知