C. Quiz 贪心 + 数学
http://codeforces.com/problemset/problem/337/C
题意是给出n个题目,那个人答对了m道,然后如果连续答对了k道,就会把分数double
求最小的分数是什么。
思路是首先看看n个位置能放下多少个(k - 1),也就是先保证不double
比如8能放下多少个3 - 1?能放下3个,mx = n / k + (n % k == k - 1)
那么就是如果答对了6题的话,最小的分数将会是6。
然后如果有多余的,就只能是和前面的连接在一起,double了。
如果后面的n % k != k - 1,那么还有n % k个空位可以放。剩下的,就只能和前面的double了。
优先把前面的double,分数会最小。
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <bitset>
const int MOD = 1e9 + ;
bool check(int val) {
int en = (int)sqrt(val * 1.0);
for (int i = ; i <= en; ++i) {
if (val % i == ) return false;
}
return true;
}
LL quick_pow(LL a, LL b, LL MOD) {
LL base = a % MOD;
LL ans = ;
while (b) {
if (b & ) {
ans = (ans * base) % MOD;
}
base = (base * base) % MOD;
b >>= ;
}
return ans;
}
void work() {
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
if (k > m) {
cout << m << endl;
return;
}
int mx = n / k + (n % k == (k - ));
if (mx * (k - ) >= m) {
printf("%d\n", m);
return;
}
LL dis = m - mx * (k - );
if (n % k != k - ) {
dis -= n % k;
}
if (dis <= ) {
cout << m << endl;
return;
}
LL ans = 1LL * (mx - dis) * (k - ) % MOD;
LL tans = (quick_pow(, dis + , MOD) + MOD - ) % MOD;
tans = (tans * k) % MOD;
ans = (ans + tans) % MOD;
if (n % k != k - ) {
ans = (ans + n % k) % MOD;
}
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
#endif
// cout << check(12) << endl;
work();
return ;
}
7 6 3
C. Quiz 贪心 + 数学的更多相关文章
- 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...
- 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)
由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...
- Codeforces Round #330 (Div. 1) A. Warrior and Archer 贪心 数学
A. Warrior and Archer Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/594 ...
- codeforces 337C Quiz(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Quiz Manao is taking part in a quiz. The ...
- Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)
A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- 贪心+数学【p3156】 [CQOI2011]分金币 ([HAOI2008]糖果传递)
题目描述 圆桌上坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数目相等.你的任务是求出被转手的金币数量的最小值. 分析: 设: 每个人最 ...
- Codeforces 402D Upgrading Array:贪心 + 数学
题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中 ...
- BZOJ 3119 Book (贪心+数学推导)
手动博客搬家: 本文发表于20191029 22:49:41, 原地址https://blog.csdn.net/suncongbo/article/details/78388925 URL: htt ...
- Codeforces Round #494 (Div. 3) D. Coins and Queries (贪心,数学)
题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如 ...
随机推荐
- Cats transport(codeforces311B)(斜率优化)
\(Cats Transport\) 感觉这道题题面不好讲,就自翻了一个新的,希望有助于大家理解其思路: 大致题意: \(wch\) 的家里有 \(N\) 座山(山呈直线分布,第 \(i-1\) 座山 ...
- js对闭包的理解
原文链接http://www.jb51.net/article/24101.htm,讲的很好,清晰明了.
- jdbc navcat for mysql 连不上远程服务器的原因(安全组设置)
如果你权限,防火墙什么都设置好了,但是还是连不上远程数据库, 那么你就必须要看看你的服务器上安全组的设置(很重要) 这里以阿里云为例子(之前用阿里云服务都没设置),现在阿里云的服务器租的时候就要求配置 ...
- IDEA maven dependency自动提示
通过File->setting->maven->repositories,选择本地仓库,点击右上角更新,更新maven仓库索引 在pom.xml编写引入依赖的jar包时,已经下载到本 ...
- lucene 5的测试程序——API变动太大
package hello; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import ...
- hadoop Namenode因硬盘写满无法启动
当写元数据的分区写满,可能导致namenode挂掉从而导致及时清理出大块的空间也无法启动namenode,那此时系统namenode会报错 org.apache.hadoop.hdfs.server. ...
- 【CQOI2009】中位数图
[题目链接] 点击打开链接 [算法] 将小于m的数看作-1,大于m的看作1 然后求前缀和,如果区间[l,r]的中位数是m,显然有 : sum(r) - sum(l-1) = 0 因此,只需m的位置之前 ...
- Map集合的几种遍历方式
Map<String ,String> map=new HashMap<String,String>(); map.put("1","value1 ...
- 洛谷P4316绿豆蛙的归宿——期望
题目:https://www.luogu.org/problemnew/show/P4316 期望水题,从终点向起点推,因为是DAG,所以拓扑序推过去即可. 代码如下: #include<ios ...
- page-break-before和page-break-after
page-break-before和page-break-after CSS属性并不会修改网页在屏幕上的显示,这两个属性是用来控制文件的打印方式. 每个打印属性都可以设定4种设定值:auto.alwa ...