Codeforces Round #334 (Div. 2)
#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;
}
题意:问所有的方案%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)的更多相关文章
- 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 ...
- Codeforces Round #334 (Div. 2) D. Moodular Arithmetic 环的个数
D. Moodular Arithmetic Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/60 ...
- Codeforces Round #334 (Div. 2) C. Alternative Thinking 贪心
C. Alternative Thinking Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/6 ...
- 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 ...
- 「日常训练」Alternative Thinking(Codeforces Round #334 Div.2 C)
题意与分析 (CodeForces - 603A) 这题真的做的我头疼的不得了,各种构造样例去分析性质... 题意是这样的:给出01字符串.可以在这个字符串中选择一个起点和一个终点使得这个连续区间内所 ...
- 「日常训练」More Cowbell(Codeforces Round #334 Div.2 B)
题意与分析(CodeForces 604B) 题意是这样的:\(n\)个数字,\(k\)个盒子,把\(n\)个数放入\(k\)个盒子中,每个盒子最多只能放两个数字,问盒子容量的最小值是多少(水题) 不 ...
- Codeforces Round #334 (Div. 1) C. Lieges of Legendre
Lieges of Legendre 题意:有n堆牛,每堆有ai头牛.两个人玩一个游戏,游戏规则为: <1>从任意一个非空的堆中移走一头牛: <2>将偶数堆2*x变成k堆,每堆 ...
- 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( ...
- Codeforces Round #334(div.2) A
A. Uncowed Forces time limit per test 1 second memory limit per test 256 megabytes input standard in ...
随机推荐
- yii抛出错误页面CHttpException
public void __construct(integer $status, string $message=NULL, integer $code=0) $status integer HTTP ...
- 解决Idea创建maven-archetype-webapp项目无java目录的问题
一.背景 在适用IDEA创建maven-archetype-webapp项目的时候,创建完成后发现在main文件夹下没有java源文件夹,不少小伙伴也遇到该问题,但不知道怎么解决,下面我就来分享解决步 ...
- bat批量删.svn
==================1======================= Bat代码 收藏代码 @echo off :start ::启动过程,切换目录 set pwd=%cd% cd % ...
- Java bean validation 规范与参考实现
1.Apache Bval 依赖包:validation-api-1.1.0.Final.jar org.apache.bval.bundle-1.1.1.jar bval-core-1.1.1.ja ...
- Cocoapods的使用教程
前言 对于iOS App的开发,几乎都采用了Cocoapods来管理第三方库,那么对于我们开发人员来说,这是必备技能,必须要掌握如何使用.这篇文章就是介绍如何安装和使用CocoaPods的. 这篇文章 ...
- hdu2030 汉字统计
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2030 解题思路:主要考察汉字的编码方式, 汉字机内码在计算机的表达方式的描述是,使用二个字节,汉字的每 ...
- Html和CSS的关系
1. HTML是网页内容的载体.内容就是网页制作者放在页面上想要让用户浏览的信息,可以包含文字.图片.视频等. 2. CSS样式是表现.就像网页的外衣.比如,标题字体.颜色变化,或为标题加入背景图片. ...
- 【转载】pyqt QTableWidget的使用
转载地址: http://blog.sina.com.cn/s/blog_9b78c91101019sgi.html QTableWidget是QT程序中常用的显示数据表格的空间,很类似于VC.C#中 ...
- Jmeter在restful风格接口测试中的应用
1.如何下载安装 官网下载,一个压缩包apache-jmeter-3.0.zip,解压即可,打开bin目录下jmeter.bat即可打开软件. 2.熟悉界面 3.实际案例 测试restful风格接口 ...
- 以16进制打印出一块内存buff
如下代码(支持windows与Linux)会以[16进制][每行16字节]打印出一块内存的内容: void PrintBuffer(void* pBuff, unsigned int nLen) { ...