zoukankan      html  css  js  c++  java
  • Codeforces Round #657 (Div. 2)B. Dubious Cyrpto

    思路

    题目要求:

    [na+b-c=m ]

    我们可以转换为

    [na-m=c-b ]

    然后(c-b)是固定不变的,我们去枚举a,在枚举的a的时候我们发现要使等式尽可能的成立只有让(na-m)的差值绝对值越小越好,然后我们会发现(na)(m)的左右两侧时,差值绝对值最小。

    比如说

    [2*a……m……3*a ]

    我们让m将在他们中间,此时的差值绝对值是最小的。

    然后枚举(a)即可。

    其中求解左边系数时只有当(i<m)才会有左边的系数。

    因为当(igeq m)时,此时(n)无论取何止都是在(m)的右侧。

    所以我们要分开讨论。

    (|m\%i|)就是左边的差值,(|a-m\%i|)就是右边的差值。然后找最小的可能。

    #include<bits/stdc++.h>
    #define INF 0x3f3f3f3f
    #define DOF 0x7f7f7f7f
    #define endl '
    '
    #define mem(a,b) memset(a,b,sizeof(a))
    #define debug(case,x); cout<<case<<"  : "<<x<<endl;
    #define open freopen("ii.txt","r",stdin)
    #define close freopen("oo.txt","w",stdout)
    #define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pb push_back
    using namespace std;
    //#define int long long
    #define lson rt<<1
    #define rson rt<<1|1
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef pair<long long,long long> PII;
    const int maxn = 1e6 + 10;
    
    
    
    void solve() {
        ll l,r,m;cin>>l>>r>>m;
    
    
        ll lf=l-r,rf=r-l;
    
        for(int i=l;i<=r;++i){
            if(m>i){
                if(m%i<=rf){
                    cout<<i<<" "<<l+m%i<<" "<<l<<endl;break;
                }else if(i-m%i<=rf){
                    cout<<i<<" "<<r-(i-m%i)<<" "<<r<<endl;break;
                }
            }else if(i>=m&&i-m<=rf){
                cout<<i<<" "<<r-i+m<<" "<<r<<endl;
                break;
            }
        }
    
    
    
    }
    
    
    int main() {
        int __;
        cin >> __;
    //    scanf("%d",&__);
        while(__--) {
            solve();
        }
    
    }
    
    

    B. Dubious Cyrpto
    time limit per test1 second
    memory limit per test512 megabytes
    inputstandard input
    outputstandard output
    Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l≤a,b,c≤r, and then he computes the encrypted value m=n⋅a+b−c.

    Unfortunately, an adversary intercepted the values l, r and m. Is it possible to recover the original values of a, b and c from this information? More formally, you are asked to find any values of a, b and c such that

    a, b and c are integers,
    l≤a,b,c≤r,
    there exists a strictly positive integer n, such that n⋅a+b−c=m.
    Input
    The first line contains the only integer t (1≤t≤20) — the number of test cases. The following t lines describe one test case each.

    Each test case consists of three integers l, r and m (1≤l≤r≤500000, 1≤m≤1010). The numbers are such that the answer to the problem exists.

    Output
    For each test case output three integers a, b and c such that, l≤a,b,c≤r and there exists a strictly positive integer n such that n⋅a+b−c=m. It is guaranteed that there is at least one possible solution, and you can output any possible combination if there are multiple solutions.

  • 相关阅读:
    求大神回答这个管理系统不知道为啥不成功急!
    这个函数到底什么意思如何调用
    判断浮点数是否为零的问题
    字符串与列表的 常用方法
    变量名命名规范 运算符 流程控制
    ACM C++
    struts s:iterator循环遍历数据 自动生成序号
    JAVA将一个EXCEL多行订单产品字符串分解成一个个子订单 +连接符连接
    JS在HTML中获取到所有选中的checkbox的值
    自己做的java-WEB项目。希望360浏览器能够默认使用极速模式打开
  • 原文地址:https://www.cnblogs.com/waryan/p/13374502.html
Copyright © 2011-2022 走看看