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 贪心 + 数学的更多相关文章

  1. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  2. 洛谷3月月赛div2 题解(模拟+数学+贪心+数学)

    由于本人太蒻了,div1的没有参加,胡乱写了写div2的代码就赶过来了. T1 苏联人 题目背景 题目名称是吸引你点进来的. 这是一道正常的题,和苏联没有任何关系. 题目描述 你在打 EE Round ...

  3. 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 ...

  4. codeforces 337C Quiz(贪心)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud Quiz Manao is taking part in a quiz. The ...

  5. Codeforces Round #300(A.【字符串,多方法】,B.【思维题】,C.【贪心,数学】)

    A. Cutting Banner time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  6. 贪心+数学【p3156】 [CQOI2011]分金币 ([HAOI2008]糖果传递)

    题目描述 圆桌上坐着n个人,每人有一定数量的金币,金币总数能被n整除.每个人可以给他左右相邻的人一些金币,最终使得每个人的金币数目相等.你的任务是求出被转手的金币数量的最小值. 分析: 设: 每个人最 ...

  7. Codeforces 402D Upgrading Array:贪心 + 数学

    题目链接:http://codeforces.com/problemset/problem/402/D 题意: 给你一个长度为n的数列a[i],又给出了m个“坏质数”b[i]. 定义函数f(s),其中 ...

  8. BZOJ 3119 Book (贪心+数学推导)

    手动博客搬家: 本文发表于20191029 22:49:41, 原地址https://blog.csdn.net/suncongbo/article/details/78388925 URL: htt ...

  9. Codeforces Round #494 (Div. 3) D. Coins and Queries (贪心,数学)

    题意:给你一组全是\(2^d\ (d\ge0)\)的数,询问q次,每次询问一个数,问这个数是否能够由原数组中的数相加得到,如果能,输出最少用多少个数,否则输出\(-1\). 题解:首先贪心得出结论:如 ...

随机推荐

  1. 在Windows上使用libcurl发起HTTP请求

    curl下载地址https://curl.haxx.se/download.html 当前最新版本为7.61.0 将下载的curl-7.61.0.zip解压,得到curl-7.61.0 在目录curl ...

  2. 百度语音识别开放平台SDK用法

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/zpf8861/article/details/30229039 百度Android语音识别SDK分在 ...

  3. Android设备adb授权的原理【转】

    本文转载自:http://blog.csdn.net/zahuopuboss/article/details/50831171 http://blog.csdn.net/sowhat_ah/artic ...

  4. 装饰器模式(IO流案例)

    装饰器模式,也成为包装模式,顾名思义,就是对已经存在的某些类进行装饰,以此来扩展一些功能.其结构图如下: Component为统一接口,也是装饰类和被装饰类的基本类型. ConcreteCompone ...

  5. CentOS 7中ip命令将逐渐取代 ifconfig

    首先看下图: 要安装ip,请点击这里下载iproute2套装工具 .不过,大多数Linux发行版已经预装了iproute2工具. 你也可以使用git命令来下载最新源代码来编译: $ git clone ...

  6. Getting Started with the Intel Media SDK

    By Gael Hofemeier on March 19, 2015 Follow Gael on Twitter: @GaelHof Media SDK Developer’s Guide Med ...

  7. async-await原理解析

    在用async包裹的方法体中,可以使用await关键字以同步的方式编写异步调用的代码.那么它的内部实现原理是什么样的呢?我们是否可以自定义await以实现定制性的需求呢?先来看一个简单的例子: cla ...

  8. virtualbox 复制虚拟机提示uuid is exists

    C:\Program Files\Oracle\VirtualBox>VBoxManage.exe internalcommands sethduuid D:毛毛草\virtual\ubuntu ...

  9. 【系列】 2-SAT

    bzoj 1997 Planar 题目大意: 给一个存在曼哈顿回路的无向图,求该图是否为平面图 思路: 先把曼哈顿回路提出来,则剩下的边的两个端点若有$ABAB$的形式则这两条边必定一个在环外一个在环 ...

  10. POJ2443 Set Operation (基础bitset应用,求交集)

    You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't ...