水 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. 根据OSG中的ref_ptr和Reference简化的智能指针

    main.cpp测试代码 #include "TestSmartPointer" void fun() { SP<TestSmartPointer> sp1=new T ...

  2. SQLServer自定义函数简单演示

    CREATE FUNCTION [ schema_name. ] function_name ( [ { @parameter_name [ AS ][ type_schema_name. ] par ...

  3. python中的时间处理函数

    Python提供了多个内置模块用于操作日期时间,像calendar,time,datetime.time模块我在之前的文章已经有所介绍,它提供 的接口与C标准库time.h基本一致.相比于time模块 ...

  4. 资源监控工具--spotlight

    1.被监控服务器为Ubuntu server,先在服务器上创建一个用户,专门用于监控使用! 因为远程监控服务器,需要获取服务器的资源,所以必须要有权限.使用文档明确说明,不能使用root用户,但是我用 ...

  5. Android OkHttp完全解析 --zz

    参考文章 https://github.com/square/okhttp http://square.github.io/okhttp/ 泡网OkHttp使用教程 Android OkHttp完全解 ...

  6. 谈谈Delph中的类和对象2---类可以理解成一种特殊的数据结构、类型转换

    三.类可以理解成一种特殊的数据结构 我们知道数据类型可以进行强制类型转换,类既然可以理解成一种数据类型,那么它也应该可以进行类型转换.比如下面代码为一个按钮(Button1)的单击事件 procedu ...

  7. 25条提高Visual Studio编码和调试效率的技巧

    (此文章同时发表在本人微信公众号"dotNET每日精华文章",欢迎右边二维码来关注.) 题记:工欲善其事必先利其器.就算手中已经有了利器,如果能掌握一些使用工具的技巧,让利器更加顺 ...

  8. 安装VS2010水晶报表插件

    Visual Studio 2010默认不带水晶报表,需要安装一个水晶报表插件,首先下载此插件: http://downloads.businessobjects.com/akdlm/cr4vs201 ...

  9. ARM伪指令,王明学learn

    ARM伪指令 在ARM汇编语言程序中里,有一些特殊指令助记符与指令系统的助记符不同,没有相对应的操作码,通常称这些特殊指令助记符为伪指令,他们所完成的操作称为伪操作.伪指令在元程序中的作用是为完成汇编 ...

  10. 10个很棒的学习Android 开发的网站(转)

    看到江湖旅人 写的<10个很棒的学习iOS开发的网站 - 简书>,所以就忍不住写Android 啦,也希望对大家有帮助.我推荐的网站,都是我在学习Android 开发过程中发现的好网站,给 ...