MemSQL Start[c]UP 2.0 - Round 2 - Online Round A,B,C

MemSQL Start[c]UP 2.0 - Round 2 - Online Round

题目链接

不得不说这场真心不好打啊...

A:黄金分割进制数,满足一个性质,对于第i位xi=xi?1+xi?2,这样一来就可以把所有位推到前两位去比较大小,不过单单这样直接搞果断爆longlong无限WA8,最后发现在推的过程中,有一位上面差值大于1,就可以直接判断了

B:不得不吐槽一下毛子的英语,Today‘s ying yu is very hao,题目看了非常非常久,不能更逗。其实看懂的就挺简单了,只要贪心分别考虑A放入B和B放入A的情况,然后判断是用复制好还是移动好即可

C:三分,设f(x)为其他人选票都小于x,自己选票大于等于x需要的开销,这样一开很容易证明f(x)是一个下凹的单峰函数,就可以用三分法求解了

代码:

A:

#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

const double eps = 1e-10;
const int N = 100005;

char A[N], B[N];
long long a[N], b[N];

int main() {
    scanf("%s%s", A, B);
    int an = strlen(A);
    int bn = strlen(B);
    for (int i = 0; i <  an; i++)
	a[i] = A[an - i - 1] - '0';
    for (int i = 0; i < bn ; i++)
	b[i] = B[bn - i - 1] - '0';
    int n = max(an, bn);
    for (int i = n - 1; i >= 2; i--) {
	if (a[i] >= b[i] ){
	    a[i] -= b[i];
	    b[i] = 0;
	}
	else if (a[i] <= b[i]) {
	    b[i] -= a[i];
	    a[i] = 0;
	}
	if (a[i] >= 2) {
	    printf(">\n");
	    return 0;
	}
	if (b[i] >= 2) {
	    printf("<\n");
	    return 0;
	}
	a[i - 1] += a[i]; a[i - 2] += a[i];
	b[i - 1] += b[i]; b[i - 2] += b[i];
    }
    long long aa = a[0], bb = a[1];
    long long cc = b[0], dd = b[1];
    long long x = 2 * (aa - cc) - (dd - bb);
    long long y = (dd - bb);
    if (x < 0 && y > 0) {
	printf("<\n");
    }
    else if (x > 0 && y < 0) {
	printf(">\n");
    }
    else if (x >= 0 && y >= 0) {
	x = x * x;
	y = y * y * 5;
	if (x == y) printf("=\n");
	else if (x < y) printf("<\n");
	else printf(">\n");
    }
    else {
	x = x * x;
	y = y * y * 5;
	if (x == y) printf("=\n");
	else if (x < y) printf(">\n");
	else printf("<\n");
    }
    return 0;
}

B:

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

typedef unsigned long long ll;

const int N = 100005;

ll a[N], b[N], suma, sumb, n, m;

int main() {
    scanf("%llu%llu", &n, &m);
    for (int i = 0; i < n; i++) {
	scanf("%llu", &a[i]);
	suma += a[i];
    }
    for (int i = 0; i < m; i++) {
	scanf("%llu", &b[i]);
	sumb += b[i];
    }
    sort(a, a + n);
    sort(b, b + m);
    ll ans = 10000000000000000000ULL;
    ll sum = 0;
    for (ll i = 0; i < n - 1; i++) {
	if (sumb <= a[i]) {
	    sum += (n - i) * sumb;
	    ans = min(ans, sum);
	    break;
	}
	sum += a[i];
    }
    ans = min(ans, sum + sumb);
    sum = 0;
    for (ll i = 0; i < m - 1; i++) {
	if (suma <= b[i]) {
	    sum += (m - i) * suma;
	    ans = min(ans, sum);
	}
	sum += b[i];
    }
    ans = min(ans, sum + suma);
    printf("%llu\n", ans);
    return 0;
}

C:

#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 100005;

int n, save[N];
vector<int> g[N];

int cal(int x) {
    int ans = 0, have = g[0].size(), sn = 0;
    for (int i = 1; i <= 100000; i++) {
	int j = 0;
	if (x <= g[i].size()) {
	    for (; j < g[i].size() - x + 1; j++) {
		ans += g[i][j];
		have++;
	    }
	}
	for (; j < g[i].size(); j++)
	    save[sn++] = g[i][j];
    }
    sort(save, save + sn);
    for (int i = 0; i < x - have; i++)
	ans += save[i];
    return ans;
}

int main() {
    scanf("%d", &n);
    int a, b;
    for (int i = 0; i < n; i++) {
	scanf("%d%d", &a, &b);
	g[a].push_back(b);
    }
    for (int i = 1; i <= 100000; i++)
	sort(g[i].begin(), g[i].end());
    int l = 1, r = n;
    while (l < r - 2) {
	int midl = (l * 2 + r) / 3;
	int midr = (l + r * 2) / 3;
	if (cal(midl) > cal(midr)) l = midl;
	else r = midr;
    }
    int ans = INF;
    for (int i = l; i <= r; i++)
	ans = min(ans, cal(i));
    printf("%d\n", ans);
    return 0;
}

MemSQL Start[c]UP 2.0 - Round 2 - Online Round A,B,C

时间: 2024-08-11 01:29:41

MemSQL Start[c]UP 2.0 - Round 2 - Online Round A,B,C的相关文章

MemSQL Start[c]UP 2.0 - Round 1

搞了好久才把大部分题目题解看完了,真是太弱了. A题简单暴力题一个一个匹配,对应位置字母要么相同,要么是'.'. B题给定一个矩阵,左下角(0,0),右上角(n, m),取4个不同的点连成一段折线,要有最长的折线长度. 排除n == 0 和m == 0 ,剩下的情况中总共由4中情况: 枚举一下就可以了 1. (0,0)->(n,m)->(0, m)->(n, 0) 2. (0,0)->(n,m)->(n, 0)->(0, m) 3.(n,m-1)->(0,0)-&

MemSQL Start[c]UP 2.0 - Round 2

反正晚上睡不着,熬到1点开始做比赛,6个题目只做了2个题目,而且手速还比较慢,待提升空间还很大呢. A题:给定两个0,1串(len<=100000), 但是不是普通的二进制串,而是q进制串,q = (√5 + 1)/2,比较这两个串的大小. 分析:q的长度很大,即使用大数似乎也不怎么合理,其实我写了半天大数,用最大长度数据测试发现根本出不了结果,也许我写的太挫了,也学时间就耗在上面了. 最终只能另想方法,而且题目中也说明了q^2 = q+1,所以很容易想到利用这个来做这个题, 观察到对于一个串中

MemSQL Start[c]UP 2.0 - Round 1(无聊练手B题)

http://codeforces.com/contest/452/problem/B B. 4-point polyline time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given a rectangular grid of lattice points from (0, 0) to (n, m) inc

MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline (线段的 枚举)

昨天cf做的不好,居然挂零了,还是1点开始的呢.,,, a题少了一个条件,没判断长度. 写一下B题吧 题目链接 题意: 给出(n, m),可以得到一个矩形 让你依次连接矩形内的4个点使它们的长度和最长,而这三条线段可以相交.交叉 分析:这种情况下,枚举对角线的四个点,当时我也想过,我只用了其中的一种 方式,其实有四种方式判断,好像没什么道理. 上图吧: MemSQL Start[c]UP 2.0 - Round 1 B. 4-point polyline (线段的 枚举)

MemSQL Start[c]UP 2.0 - Round 2 - Online Round

搞到凌晨4点一个没出,要gg了. A. Golden System http://codeforces.com/contest/458/problem/A 1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 using namespace std; 6 const double q=(sqrt(5.0)+1)/2; 7 const int M=100

CF memsql Start[c]UP 2.0 A

CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Piegirl got bored with binary, decimal and other integer based counting systems. Recently she dis

Educational Codeforces Round 26 D. Round Subset(dp)

题目链接:Educational Codeforces Round 26 D. Round Subset 题意: 给你n个数,让你选其中的k个数,使得这k个数的乘积的末尾的0的个数最大. 题解: 显然,末尾乘积0的个数和因子2和因子5的个数有关. 然后考虑dp[i][j]表示选i个数,当前因子5的个数为j时,能得到因子2最多的为多少. 那么对于每个数,记录一下因子2和5的个数,做一些01背包就行了. 1 #include<bits/stdc++.h> 2 #define mst(a,b) me

MySQL四舍五入函数ROUND(x)、ROUND(x,y)和TRUNCATE(x,y)

MySQL四舍五入函数ROUND(x) ROUND(x)函数返回最接近于参数x的整数,对x值进行四舍五入. 实例: 使用ROUND(x)函数对操作数进行四舍五入操作.SQL语句如下: mysql>SELECT ROUND(-2.34),ROUND(-4.56),ROUND(2.34),ROUND(4.56); ROUND(x)函数的执行结果如下图所示: 上图中代码执行的结果显示,进行四舍五入处理以后,只保留了各个值的整数部分. MySQL四舍五入函数ROUND(x,y) ROUND(x,y)函数

Codeforces Round #437 (Div. 2, based on MemSQL Start[c]UP 3.0 - Round 2) E. Buy Low Sell High [贪心 II][数据结构 I]

题目:http://codeforces.com/contest/867/problem/E 题意:模拟股票操作,每天只能买一只股票或者卖一只股票或者什么也不做,求最大利润. 题解:仔细想想是非常简单的一个贪心问题,理解为连续的多次贪心买入卖出可以合并为一次的买入卖出,且值为最优.只需要用一个最小堆每次寻找前面的最小且没有被标记为购买点的值即可.如果自己为最小值,continue.如果那个值没有被选过,为买入点,pop.如果那个值被选为了售出的点,那么取消售出的标记,把当前点标记为售出点,利润直