A. Raising Bacteria

计算一下x的bitcount就是答案。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; int bitcount(int x)
{
int ans = ;
while(x)
{
if(x & ) ans++;
x >>= ;
}
return ans;
} int main()
{
int x; scanf("%d", &x);
printf("%d\n", bitcount(x)); return ;
}

代码君

B. Finding Team Member

贪心

从大到小排个序,如果两个人都没有舞伴那就结为一组。

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = + ; struct FK
{
int r, c, d;
FK() {}
FK(int r, int c, int d):r(r), c(c), d(d) {} bool operator < (const FK& a) const
{
return d > a.d;
}
}fk[maxn * maxn]; int n; int match[maxn]; int main()
{
int tot = ;
scanf("%d", &n); n <<= ; for(int i = ; i <= n; i++)
for(int j = ; j < i; j++)
{
int x; scanf("%d", &x);
fk[tot++] = FK(i, j, x);
} sort(fk, fk + tot); int remain = n;
for(int i = ; i < tot && remain; i++)
{
FK& e = fk[i];
int u = e.r, v = e.c;
if(!match[u] && !match[v])
{
match[u] = v;
match[v] = u;
remain -= ;
}
} for(int i = ; i < n; i++) printf("%d ", match[i]);
printf("%d\n", match[n]); return ;

代码君

C. A Problem about Polyline

题意:

给出 (0, 0) – (x, x) – (2x, 0) – (3x, x) – (4x, 0) – ... - (2kx, 0) – (2kx + x, x) – .... 这样一条折线,和上面一点(a, b)。求可能的最小的x

分析:

首先(a, b)与原点连线的斜率最大是1,绝对不会超过1. 所以一开始判断一下,如果b > a,无解。

分情况讨论(a, b)是上升点还是下降点:

  • (a, b)是上升点,那么点(a - b, 0)一定在折线上,所以得到 a - b = 2kx (k是正整数)。x = (a - b) / (2k),注意到折线上的点纵坐标最大值为x,所以x应该满足x≥b。所以有k ≤ (a - b) / (2b),k取最大值时,x取得最小值。
  • (a, b)是下降点,和前一种情况一样。点(a + b, 0)一定在折线上,后面的分析思路和上面一样。

这两种情况算出来两个x的最小值再取最小值就是答案。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL; int main()
{
LL a, b; cin >> a >> b; if(b > a) { puts("-1"); return ; }
if(a == b) { printf("%I64d.000000000000\n", a); return ; } double x1, x2;
LL k = (a - b) / (b * );
x1 = 1.0 * (a - b) / 2.0 / k;
k = (a + b) / (b * );
x2 = 1.0 * (a + b) / 2.0 / k;
x1 = min(x1, x2); printf("%.12f\n", x1); return ;
}

代码君

D. "Or" Game

这个题是贪心,但是有种黑科技的赶脚,目前没想明白贪心的理由。

贪心的方法是:既然操作不超过k次,那么k次操作直接用在同一个数上面。然后枚举k次操作在哪个数上面,预处理一下前缀后缀的或运算的值,时间复杂度为O(n)。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; typedef long long LL; const int maxn = + ; LL a[maxn], pre[maxn], suf[maxn]; int main()
{
int n, k;
LL x;
scanf("%d%d%I64d", &n, &k, &x); for(int i = ; i <= n; i++)
{
scanf("%I64d", a + i);
pre[i] = pre[i - ] | a[i];
}
for(int i = n; i > ; i--) suf[i] = suf[i + ] | a[i]; LL x0 = x;
for(int i = ; i <= k; i++) x *= x0; LL ans = ;
for(int i = ; i <= n; i++) ans = max(ans, pre[i-] | (a[i] * x) | suf[i+]); printf("%I64d\n", ans); return ;
}

代码君

E. Weakness and Poorness

很明显,当x向两边趋于正负很大的数的时候,序列{ ai - x }的weakness也是变大的。

但不明显的一点就是,为什么中间只有一个极值?

如果中间只有一个极值的话,就可以用三分找到对应的极小值,同时也是最小值。

关于weakness的计算:

我们可以用线性时间的DP来计算数列的最大连续子序列

d(i)表示以ai结尾的子序列的最大值,状态转移为d(i) = max{ d(i-1) + ai, ai }

同样地,再计算一个最小连续子序列,取两者绝对值的最大值就是整个序列的weakness

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; const int maxn = + ;
const double eps = 1e-; int n;
double a[maxn]; double Calc(double x)
{
double ans = , p = , q = ;
for(int i = ; i <= n; i++)
{
double t = a[i] - x;
if(p > ) p += t; else p = t;
if(q < ) q += t; else q = t;
ans = max(ans, max(p, -q));
} return ans;
} int main()
{
//freopen("in.txt", "r", stdin); scanf("%d", &n);
for(int i = ; i <= n; i++) scanf("%lf", a + i); //printf("%.7f\n%.7f\n", Calc(2), Calc(1.75)); double L = -1e5, R = 1e5, ans;
for(;;)
{
double t = (R - L) / 3.0;
double Lmid = L + t, Rmid = R - t;
double ansL = Calc(Lmid), ansR = Calc(Rmid); if(fabs(ansL - ansR) < eps) { ans = ansL; break; } if(ansL > ansR) L = Lmid;
else R = Rmid;
} printf("%.7f\n", ans); return ;
}

代码君

CodeForces Round #320 Div2的更多相关文章

  1. Codeforces Round#320 Div2 解题报告

    Codeforces Round#320 Div2 先做个标题党,骗骗访问量,结束后再来写咯. codeforces 579A Raising Bacteria codeforces 579B Fin ...

  2. Codeforces Round #539 div2

    Codeforces Round #539 div2 abstract I 离散化三连 sort(pos.begin(), pos.end()); pos.erase(unique(pos.begin ...

  3. 【前行】◇第3站◇ Codeforces Round #512 Div2

    [第3站]Codeforces Round #512 Div2 第三题莫名卡半天……一堆细节没处理,改一个发现还有一个……然后就炸了,罚了一啪啦时间 Rating又掉了……但是没什么,比上一次好多了: ...

  4. Codeforces Round #564(div2)

    Codeforces Round #564(div2) 本来以为是送分场,结果成了送命场. 菜是原罪 A SB题,上来读不懂题就交WA了一发,代码就不粘了 B 简单构造 很明显,\(n*n\)的矩阵可 ...

  5. Codeforces Round #361 div2

    ProblemA(Codeforces Round 689A): 题意: 给一个手势, 问这个手势是否是唯一. 思路: 暴力, 模拟将这个手势上下左右移动一次看是否还在键盘上即可. 代码: #incl ...

  6. Codeforces Round #626 Div2 D,E

    比赛链接: Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics) D.Present 题意: 给定大 ...

  7. CodeForces Round 192 Div2

    This is the first time I took part in Codeforces Competition.The only felt is that my IQ was contemp ...

  8. [Codeforces] Round #320 (Div.2)

    1.前言 虽然这次我依旧没有参加正式比赛,但是事后还是看了看题目的...一般不怎么刷Codeforces. A.Raising Bacteria You are a lover of bacteria ...

  9. Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] C. Weakness and Poorness 三分 dp

    C. Weakness and Poorness Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/5 ...

随机推荐

  1. 关于锚点页内链接跳转出现问题(不响应,没有反应)的解决方法(ZT)

    我们知道,利用锚点可以实现页面链接跳转,也可以实现同一页面内的跳转功能. 例如:<a href="somepage.htm>某页面链接</a>  可以跳转链接到som ...

  2. SpringBoot 2.x (13):整合ActiveMQ

    ActiveMQ5.x不多做介绍了,主要是SpringBoot的整合 特点: 1)支持来自Java,C,C ++,C#,Ruby,Perl,Python,PHP的各种跨语言客户端和协议 2)支持许多高 ...

  3. ConfigurationErrorsException: Unrecognized configuration section system.data.

    报错 ConfigurationErrorsException: Unrecognized configuration section system.data. (C:\Users\luren\Sou ...

  4. CF1157D N Problems During K Days

    思路: 在1, 2, 3, ... , k的基础上贪心构造. 实现: #include <bits/stdc++.h> using namespace std; typedef long ...

  5. python+selenium之验证码的处理

    对于web应用来说,大部分的系统在用户登录时都要求用户输入验证码.验证码的类型很多,有字母数字的,有汉字的.甚至还有需要用户输入一道算术题的答案的.对于系统来说,使用验证码可以有效地防止采用机器猜测方 ...

  6. 【TensorFlow入门完全指南】神经网络篇·循环神经网络(RNN)

    第一步仍然是导入库和数据集. ''' To classify images using a reccurent neural network, we consider every image row ...

  7. 如何选择Web开发框架

    下面先来看看为什么要使用Web开发框架一 使用框架的必然性框架,即framework.其实就是某种应用的半成品,把不同应用程序中有共性的一些东西抽取出来,做成一个半成品程序,这样的半成品就是所谓的程序 ...

  8. 检查windows端口被占用

    开始---->运行---->cmd,或者是window+R组合键,调出命令窗口 输入命令:netstat -ano,列出所有端口的情况.在列表中我们观察被占用的端口,比如是49157,首先 ...

  9. java面试题(杨晓峰)---第二讲Exception和Error有什么区别?

    本人总结: Exception和Error:正常问题和意外问题,以自行车举例:没气和爆胎. ①理解Throwable,Exception,Error的设计和分类. ②掌握哪些应用最广泛的子类, ③如何 ...

  10. ABAP vs Java, 蛙泳 vs 自由泳

    去年7月定下的一年之内学会自由泳的目标终于实现了,特来还愿. ABAP和Java, 蛙泳和自由泳.前面的组合是Jerry用来挣钱养家的技术,后者是Jerry花了大量业余时间和金钱苦练的技能.或许有的朋 ...