Minimum Integer CodeForces - 1101A (思维+公式)
You are given qq queries in the following form:
Given three integers lili, riri and didi, find minimum positive integer xixi such that it is divisible by didi and it does not belong to the segment [li,ri][li,ri].
Can you answer all the queries?
Recall that a number xx belongs to segment [l,r][l,r] if l≤x≤rl≤x≤r.
Input
The first line contains one integer qq (1≤q≤5001≤q≤500) — the number of queries.
Then qq lines follow, each containing a query given in the format lili riri didi (1≤li≤ri≤1091≤li≤ri≤109, 1≤di≤1091≤di≤109). lili, riri and didi are integers.
Output
For each query print one integer: the answer to this query.
Example
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
6
4
1
3
10 题目链接:CodeForces - 1101A水题一个,但是数据量略大不足以让我们暴力随便过。
那么便思考一下找公式就行了,
观察可知,当d小于L的时候,答案就是d
否则,答案是(r/d+1)*d; 我的AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int q;
int l,r;
int d;
int main()
{
gbtb;
cin>>q;
while(q--)
{
cin>>l>>r>>d;
int flag=;
if(d<l)
{
cout<<d<<endl;
continue;
}else
{
int ans=(r/d+)*d;
cout<<ans<<endl;
}
}
return ;
} inline void getInt(int* p) {
char ch;
do {
ch = getchar();
} while (ch == ' ' || ch == '\n');
if (ch == '-') {
*p = -(getchar() - '');
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * - ch + '';
}
}
else {
*p = ch - '';
while ((ch = getchar()) >= '' && ch <= '') {
*p = *p * + ch - '';
}
}
}
Minimum Integer CodeForces - 1101A (思维+公式)的更多相关文章
- Codeforces 424A (思维题)
Squats Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Statu ...
- CodeForces - 417A(思维题)
Elimination Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit ...
- Doors Breaking and Repairing CodeForces - 1102C (思维)
You are policeman and you are playing a game with Slavik. The game is turn-based and each turn consi ...
- CodeForces 816C 思维
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as fo ...
- CF1101A Minimum Integer 模拟
题意翻译 题意简述 给出qqq组询问,每组询问给出l,r,dl,r,dl,r,d,求一个最小的正整数xxx满足d∣x d | x\ d∣x 且x̸∈[l,r] x \not\in [l,r]x̸∈[l ...
- codeforces 1244C (思维 or 扩展欧几里得)
(点击此处查看原题) 题意分析 已知 n , p , w, d ,求x , y, z的值 ,他们的关系为: x + y + z = n x * w + y * d = p 思维法 当 y < w ...
- CodeForces - 417B (思维题)
Crash Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u Submit Status ...
- The Contest CodeForces - 813A (思维)
Pasha is participating in a contest on one well-known website. This time he wants to win the contest ...
- 3-palindrome CodeForces - 805B (思维)
In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so ...
随机推荐
- Cannot uninstall 'pyserial'. It is a distutils installed project and thus we cannot a ccurately determine which files belong to it which would lead to only a partial uninstall. 解决方法
最近再升级 pyserial模块时,采用 pip install --upgrade pyserial,待模块下载完成准备卸载原版本时 提示:“Cannot uninstall 'pyserial'. ...
- IO流_文件切割与合并
切割可以分两种方式:按文件个数切,按文件大小来切(建议用这种方式,因为按个数的话,有可能文件非常大) import java.io.File; import java.io.FileInputStre ...
- C++添加热键和捕获组合键
一.热键注册 步骤一:声明一个全局量int hotkeyId=1: 步骤二:窗体创建的时候注册: int result= RegisterHotKey(this->GetHWND(), hotk ...
- 使用KVM虚拟机遇到的问题(持续更新)
1.qemu-kvm.kvm.qemu 和 qemu-system-x86_64四种命令的差别 qemu 和 qemu-system-x86_64:启动qemu虚拟机的命令,x86_64为64位系统时 ...
- Android平台调用Web Service:线程返回值
接上文 前文中的遗留问题 对于Java多线程的理解,我曾经只局限于实现Runnable接口或者继承Thread类.然后重写run()方法.最后start()调用就算完事,可是一旦涉及死锁以及对共享资源 ...
- k8s监控api调用
k8s监控api调用 curl -s --cacert /etc/kubernetes/ssl/ca.pem -basic -u fengjian:fengjian --insecure -X GET ...
- Linux_修改hosts
文章转自 https://blog.csdn.net/mikyz/article/details/69399987 Windows用户XP的在C盘 C:WINDOWS/system32/drivers ...
- USB to UART
USB to UART: 芯片选用CH340: 电源部分连接两个电容分别是0.1微法和10微法: 晶振连接12MHz; D+ D- 连接单片机的D+ D-
- 【Codeforces Round 1132】Educational Round 61
Codeforces Round 1132 这场比赛做了\(A\).\(B\).\(C\).\(F\)四题,排名\(89\). \(A\)题\(wa\)了一次,少考虑了一种情况 \(D\)题最后做出来 ...
- chrome浏览器直接打印 - z
在地址栏敲: about:flags ,打开设置界面:停用:Enable Print Preview Registration PromosChrome快捷方式增加:--kiosk-printing这 ...