传送门

题意: 已知存在三个数a,b,c满足l <= a,b,c <= r,且m = n * a + b - c。现在告诉你l,r和m的值,需要你找到一组可行的a,b,c。

思路:

  • 枚举a,令 x = m%a,n = m/a,于是x是用取模操作得到的,所以一定有x>=0
  • 如果n >= 1且 x <= r-l,那么可以构造出b = x+l,c = l,因为一定是x < a的,所以就一定有x + l <= r。
  • 如果x > r-l,因为b - c的范围在[l-r,r-l]之间,说明b - c是一个负数,正是因为取模操作只能得到正数,实际上x=b-c+a,多加了一个a,那么b-c = x-a,设p = x-a就判断是否有p >= l-r,如果满足则可以构造出b = r+p,c=r。这种情况不用判断n是否>=1,因为b-c多加了一个a进去。

代码实现:

#include<bits/stdc++.h>
#define endl '\n'
#define null NULL
#define ll long long
#define int long long
#define pii pair<int, int>
#define lowbit(x) (x &(-x))
#define ls(x) x<<1
#define rs(x) (x<<1+1)
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
const int  inf = 0x7fffffff;
const double PI = acos(-1.0);
const double eps = 1e-6;
const ll   mod = 1e9 + 7;
const int  N = 2e5 + 5;int t, l, r, m;signed main()
{IOS;cin >> t;while(t --){cin >> l >> r >> m;for(int a = l; a <= r; a ++){int x = m % a;int n = m / a;if(n >= 1 && x <= r - l){cout << a << " " << l + x << " " << l << endl;break;}else{x = x - a;if(x >= l - r){ //如果abs(x) <= r-l时cout << a << " " << r + x << " " << r << endl;break;}}}}return 0;
}

Codeforces B. Dubious Cyrpto (枚举 / 模拟) (Round #657 Div.2)相关推荐

  1. [codeforces 1379B] Dubious Cyrpto 公式推导

    Codeforces Round #657 (Div. 2)   参与排名人数8684   错过了难得17:00比赛,可惜 [codeforces 1379B]   Dubious Cyrpto  公 ...

  2. Codeforces Round #657 (Div. 2)B. Dubious Cyrpto

    思路 题目要求: na+b−c=mna+b-c=m na+b−c=m 我们可以转换为 na−m=c−bna-m=c-b na−m=c−b 然后c−bc-bc−b是固定不变的,我们去枚举a,在枚举的a的 ...

  3. Codeforces Round #657 (Div. 2)

    A. Acacius and String 爆零!太菜了,下来终于把A题代码调AC了 #define IO ios::sync_with_stdio(false);cin.tie();cout.tie ...

  4. Codeforces Round #657 (Div. 2) B. Dubious Cyrpto(思维,数学)

    题目链接 题意: m=n⋅a+b−c(n为任意正整数),给出m的值a,b,c的范围l,r(l<=a,b,c<=r),求出a,b,c. 思路: 由推倒知0<=|b-c|<=r-l ...

  5. Codeforces Round #657 (Div. 2) B题 Dubious Cyrpto

    m是被除数,a是除数,n的商,b-c是余数.切记,考虑b-c是负数的情况.切记 !切记 ! 二话不说上代码: #include <iostream> #include <algori ...

  6. Codeforces 1379B.Dubious Cyrpto

    1 题目描述(题目链接) 2 题解   由题意得,na=m+c−bna=m+c-bna=m+c−b,则na∈[m+l−r,m+r−l]na\in [m+l-r,m+r-l]na∈[m+l−r,m+r− ...

  7. 模拟 Codeforces Round #249 (Div. 2) C. Cardiogram

    题目地址:http://codeforces.com/contest/435/problem/C 1 /* 2 题意:给一组公式,一组数据,计算得到一系列的坐标点,画出折线图:) 3 模拟题:蛮恶心的 ...

  8. 模拟 Codeforces Round #297 (Div. 2) A. Vitaliy and Pie

    题目传送门 1 /* 2 模拟:这就是一道模拟水题,看到标签是贪心,还以为错了呢 3 题目倒是很长:) 4 */ 5 #include <cstdio> 6 #include <al ...

  9. Codeforces Round #656 (Div. 3) F. Removing Leaves 贪心 + 模拟

    传送门 文章目录 题意: 思路: 题意: 思路: 首先有一个贪心策略就是每次都找一个叶子节点最多的点,让后删掉他的kkk个叶子节点,现在我们就来考虑如何模拟这个过程. 我们整一个vector<s ...

最新文章

  1. 序列到序列网络seq2seq与注意力机制attention浅析
  2. Metasploit中aggregator插件无法使用
  3. 全栈JVM框架Micronaut通向1.0版本之路
  4. 10参数_小米10和oppofindx2哪个好用 参数配置对比性能评测
  5. ActiveMQ添加商品接收消息
  6. html导航去下划线,纯CSS实现导航栏下划线跟随的示例代码
  7. LAMP集群项目四 安装apache、php及其插件
  8. python获取文件读写权限_Python 查看文件的读写权限方法
  9. import是引进外部函数吗_vue3已正式发布,你学了吗
  10. [转载]Qt之自定义界面(二)添加最小化、关闭按钮、添加背景
  11. 欢迎使用CSDN-markdown编辑器【转载】
  12. Python + Selenium WebDriver Api 知识回顾
  13. 山东省计算机考试无法报名,12月20日开始报名!山东2020年3月全国计算机等级考试注意事项来咯...
  14. Logs Viewer
  15. vbe编程真人小代码
  16. Linux命令--vi(编辑或查看文件内容)
  17. adb连接 红米5手机
  18. ABAP ALV红绿黄灯5步
  19. python 对数函数_使用Python玩转高等数学(4):对数函数
  20. ABP Vnext 5.0 EF6Core适配Oracle 解决方案

热门文章

  1. 图片人群计数模型代码运行指南
  2. 看一个师兄的操作系统视频有感
  3. bitmap的六种压缩方式,Android图片压缩(转)
  4. 解压缩的mysql_Windows 上解压缩版 MySQL 配置
  5. 给一个DIV的右上解加一个删除按钮
  6. 细说上帝视角游戏的快速创建
  7. 模拟人工洗牌。编写一个模拟人工洗牌的程序,讲洗好的牌分别发给四个人。(c语言)
  8. 使用.net编写的 短连接(短网址)服务
  9. IDEA 隐藏窗口标题栏(去掉 Win10 白色标题栏)
  10. Vue密码验证:密码必须由大写字母、小写字母、数字、特殊符号中的2种及以上类型组成