水 A - Uncowed Forces

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f; int main(void) {
int s[5] = {50, 100, 150, 200, 250};
int m[5], w[5], hs, hu;
for (int i=0; i<5; ++i) {
scanf ("%d", &m[i]);
}
for (int i=0; i<5; ++i) {
scanf ("%d", &w[i]);
}
scanf ("%d%d", &hs, &hu);
int ans = 0;
for (int i=0; i<5; ++i) {
ans += max (3 * s[i], (250 - m[i]) * s[i] * 10 / 250 - 50 * w[i]);
}
ans += hs * 100 - hu * 50;
printf ("%d\n", ans); return 0;
}

  

(二分)+贪心 B - More Cowbell

题意:n个物品最多放在k个盒子里,每个盒子最多放两个,问盒子的体积最小是多少.

分析:可以二分枚举体积大小,那么判断是否满足条件时需要贪心,如题解所说,如果k > n,那么体积就是单个中最大的.否则一定有n-k个盒子一定要放两个物品(解方程),那么优先选择组合体积小的,也就是前2 * (n - k)个物品前后组合,然后选取最大值和后面2*k-n个再取最大值就是答案.所以发现二分其实不需要用...

#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
int a[N]; int main(void) {
int n, k; scanf ("%d%d", &n, &k);
for (int i=1; i<=n; ++i) scanf ("%d", &a[i]);
int ans = a[n];;
for (int i=1; i<=n-k; ++i) {
ans = max (ans, a[i] + a[2*(n-k)-i+1]);
}
printf ("%d\n", ans); return 0;
}

二分版

#include <bits/stdc++.h>
using namespace std; typedef long long ll;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
int a[N];
bool vis[N];
int n, k; int check(int s) {
memset (vis, false, sizeof (vis));
int j = 1, ret = 0;
for (int i=n; i>=1; --i) {
if (j < i) {
if (a[j] + a[i] <= s) {
vis[j] = vis[i] = true; j++;
}
else vis[i] = true;
ret++;
}
else if (j == i) {
if (!vis[i]) ret++;
break;
}
}
return ret;
} int main(void) {
scanf ("%d%d", &n, &k);
for (int i=1; i<=n; ++i) {
scanf ("%d", &a[i]);
}
if (n == 1) {
printf ("%d\n", a[1]); return 0;
}
int l = a[n], r = a[n-1] + a[n];
while (l + 1 <= r) {
int mid = (l + r) >> 1;
if (check (mid) <= k) r = mid;
else l = mid + 1;
}
int ans = r;
printf ("%d\n", ans); return 0;
}

  

DP || 数学/构造 C - Alternative Thinking

题意:有01串,可以选取任意长度的字串进行一次翻转(0->1, 1->0), 问形如01010110或1010101的最大长度.

分析:中间断开的可能是00或11型 或者只有一个1或0型.比如1010101 -> 10101010即蓝色部分为翻转后的,可见长度+1.还有一种:1010101 -> 1010101长度+2,所以ans = min (n, ret + 2);

  下午想了很久的网上的DP做法,dp[i][j][k]表示第i位数字为j状态为k时的最大长度.主要想说我对第三维理解,k = 0表示没有改变,k=1表示改变,那么根据题意有一段是改变的,那么从1到2就是从变到不变

构造:

#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
char str[N]; int main(){
int n;
scanf ("%d%s", &n, str);
int ans = 1;
for (int i=1; i<n; ++i) {
ans += (str[i] != str[i-1]);
}
printf ("%d\n", min (n, ans + 2)); return 0;
}

DP:

#include <bits/stdc++.h>
using namespace std; const int N = 1e5 + 5;
char str[N];
int dp[N][2][3];
int n; void _max(int &a, int b) {
if (a < b) a = b;
} int run(void) {
memset (dp, -1, sizeof (dp));
dp[0][0][0] = dp[0][1][0] = 0;
for (int i=0; i<n; ++i) {
for (int j=0; j<2; ++j) {
for (int k=0; k<3; ++k) {
if (dp[i][j][k] == -1) continue;
for (int y=k; y<3; ++y) {
_max (dp[i+1][j][y], dp[i][j][k]);
int c = str[i+1] - '0';
if (y == 1) c ^= 1;
if (c != j) {
_max (dp[i+1][c][y], dp[i][j][k] + 1);
}
}
}
}
}
int ret = 0;
for (int i=0; i<2; ++i) {
for (int j=0; j<3; ++j) {
_max (ret, dp[n][i][j]);
}
}
return ret;
} int main(void) {
scanf ("%d", &n);
scanf ("%s", str + 1);
printf ("%d\n", run ()); return 0;
}

  

置换群 D - Moodular Arithmetic

题意:问所有的方案%MOD使得:f(k*x%p) == k * f(x) % p

分析:考虑特殊的情况,k=0, f(0) = 0, 其他随便,所以是p^(p-1); k=1,f (x) == f (x), 所以是p^p。然后考虑假设f (x1) % p = k * f (x2) % p, f (x2) % p = k * f (x3)% p.....最后有f (x1) = k ^ m * f (x1),显然有k ^ m = 1才能成立。循环节长度为m,个数有(p - 1) / m(?),x1的选则有p种,所以答案是 p ^ ((p-1) / m)

#include <bits/stdc++.h>
using namespace std; const int MOD = 1e9 + 7; int pow_mod(int x, int n) {
int ret = 1;
while (n) {
if (n & 1) {
ret = 1ll * ret * x % MOD;
}
x = 1ll * x * x % MOD;
n >>= 1;
}
return ret;
} int main(void) {
int p, k; scanf ("%d%d", &p, &k);
if (k == 0) {
printf ("%d\n", pow_mod (p, p-1));
}
else if (k == 1) {
printf ("%d\n", pow_mod (p, p));
}
else {
int cur = k, ord = 1;
while (cur != 1) {
cur = 1ll * cur * k % p;
ord++;
}
printf ("%d\n", pow_mod (p, (p-1)/ord));
} return 0;
}

  

Codeforces Round #334 (Div. 2)的更多相关文章

  1. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  2. Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数

    D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...

  3. Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心

    C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...

  4. Codeforces Round #334 (Div. 2) B. More Cowbell 二分

    B. More Cowbell Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/probl ...

  5. 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)

    题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...

  6. 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)

    题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...

  7. Codeforces Round #334 (Div. 1) C. Lieges of Legendre

    Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...

  8. Codeforces Round #334 (Div. 1) B. Moodular Arithmetic

    B - Moodular Arithmetic 题目大意:题意:告诉你p和k,其中(0<=k<=p-1),x属于{0,1,2,3,....,p-1},f函数要满足f(k*x%p)=k*f( ...

  9. Codeforces Round #334(div.2) A

    A. Uncowed Forces time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. 当你的IIS需要运行ASP网站时,需要这样配置下你的IIS

    1.进入Windows 7的 控制面板->程序和功能->选择左上角的 打开或关闭Windows功能 2.现在出现了安装Windows功能的选项菜单,注意选择的项目,红色箭头所示的地方都要选 ...

  2. ios电话/密码/验证码/身份证的正则表达式

    // 一 .电话号码正则表达式 -(BOOL)testPhoneNumber:(NSString *)text { NSString *regex =@"(13[0-9]|0[1-9]|0[ ...

  3. July 6th, Week 28th Wednesday, 2016

    Diligence is the mother of good fortune. 勤勉是好运之母. The mother of good fortune can be diligence, conti ...

  4. Stanford大学机器学习公开课(三):局部加权回归、最小二乘的概率解释、逻辑回归、感知器算法

    (一)局部加权回归 通常情况下的线性拟合不能很好地预测所有的值,因为它容易导致欠拟合(under fitting).如下图的左图.而多项式拟合能拟合所有数据,但是在预测新样本的时候又会变得很糟糕,因为 ...

  5. 线程变量ThreadLocal的使用

    我们有时候会通过token进行多次查询(猪:token是redis中的key),比如: 一次是在登录拦截器中,一次是在controller的业务中查询,这样存在性能和资源的浪费问题!!! 那么如何将拦 ...

  6. zipArchive

    ZipArchive *unZip = [[ZipArchive alloc]init]; if ([unZip unzipOpenFile:savePath]) { BOOL ret = [unZi ...

  7. 【转】C语言快速幂取模算法小结

    (转自:http://www.jb51.net/article/54947.htm) 本文实例汇总了C语言实现的快速幂取模算法,是比较常见的算法.分享给大家供大家参考之用.具体如下: 首先,所谓的快速 ...

  8. hdu1115(计算多边形几何重心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1115 题意:给出一些点,求这些点围成的多边形的重心: 思路: 方法1:直接分别求所有点的x坐标的平均值 ...

  9. iOS开发Xcode7真机调试教程

    从Xcode7开始,Xcode 不需要$99/$299升级开发者直接可以进行真机调试 调试步骤 1.假设已经你已经有了苹果账号,下载并安装好了Xcode7 2. 打开Xcode-> Prefer ...

  10. traceroute

    把跳数设置为10次: ]# traceroute -m www.baidu.com traceroute to www.baidu.com ( hops max, byte packets 10.10 ...