首页 > 其他分享 >2024.12.2 周一

2024.12.2 周一

时间:2024-12-02 22:37:18浏览次数:4  
标签:2024.12 cout int res long -- 周一 define

2024.12.2 周一


Q1. 1100

给定一个数字(32位以内),使用1,0,-1构造二进制数位,同时保证不能有相邻的非0数存在。

Q2. 1200

给定2个相同数位的数(<=1e100),任意操作:交换2数中相同位的数字使两数之积最大。

Q3. 1300

前缀后缀板题

Q4. 1400

给定n,m(<=2e6)。a:1n,b:1m,问:满足a+b是b*gcd(a,b)倍数的(a,b)对数。

------------------------独自思考分割线------------------------

A1.

发现只需将原本二进制数位中的连续的1替换:1 1 1 0->-1 0 0 1

A2.

发现操作不改变2数之和,则2数之差越小,积则越大。也可直观想象。

操作就是找到最高位不同的数给a,其余每位最大的数给b。

A3.

A4.

数学

------------------------代码分割线------------------------

A1.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n;
    cin >> n;
    vector<int> res;
    while (n)
    {
        res.push_back(n & 1);
        n >>= 1;
    }
    res.push_back(0);
    n = res.size();

    for (int i = 0; i < n; i++)
        if (res[i])
        {
            int j = i + 1;
            for (; j < n && res[j]; j++)
                res[i] = -1, res[j] = 0;
            if (j > i + 1) // j位置特判
                res[j] = 1;
            i = j - 1;
        }
    cout << res.size() << endl;
    for (auto v : res)
        cout << v << ' ';
    cout << endl;
}

A2.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    string a, b;
    cin >> a >> b;
    // cout << stoll(a) * stoll(b) << endl;
    int f = 0;
    for (int i = 0; i < a.size(); i++)
        if (!f)
        {
            if (a[i] - b[i])
                f = 1;
            if (a[i] < b[i])
                swap(a[i], b[i]);
        }
        else
        {
            if (a[i] > b[i])
                swap(a[i], b[i]);
        }
    cout << a << endl
         << b << endl;
}

A3.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n + 2), pre(n + 2), repre(n + 2);
    for (int i = 1; i <= n; i++)
        cin >> a[i], pre[i] = pre[i - 1] + a[i];
    for (int i = n; i; i--)
        repre[i] = repre[i + 1] + a[i];
    int l, r;
    for (l = 1; l <= n; l++)
        if (pre[l] > k - k / 2)
            break;
    for (r = n; r; r--)
        if (repre[r] > k >> 1)
            break;
    int res = n - max(0ll, r - l + 1);
    if (pre[n] <= k)
        res = n;
    cout << res << endl;
}

A4.

#include <bits/stdc++.h>
#define int long long //
#define endl '\n'     // 交互/调试 关
using namespace std;
#define bug(BUG) cout << "bug:# " << (BUG) << endl
#define bug2(BUG1, BUG2) cout << "bug:# " << (BUG1) << " " << (BUG2) << endl
#define bug3(BUG1, BUG2, BUG3) cout << "bug:# " << (BUG1) << ' ' << (BUG2) << ' ' << (BUG3) << endl
void _();
signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(6);
    int T = 1;
    cin >> T;
    while (T--)
        _();
    return 0;
}

void _()
{
    int n, m;
    cin >> n >> m;
    int res = 0;
    for (int b = 1; b <= m; b++)
        res += (n + b) / b / b;
    cout << res - 1 << endl;
}

标签:2024.12,cout,int,res,long,--,周一,define
From: https://www.cnblogs.com/jkkk/p/18582882

相关文章

  • 2024.12.3(周二)
    #导入必要的库fromsklearnimportdatasetsfromsklearn.model_selectionimporttrain_test_split,cross_val_score,StratifiedKFoldfromsklearn.svmimportSVCfromsklearn.metricsimportaccuracy_score,precision_score,recall_score,f1_score,classification......
  • 2024.12.2(周一)
    importnumpyasnpfromsklearnimportdatasetsfromsklearn.model_selectionimporttrain_test_split,cross_val_scorefromsklearn.metricsimportaccuracy_score,precision_score,recall_score,f1_score,confusion_matrix,make_scorerfromsklearn.treeimpo......
  • 2024.12.6(周五)
    #导入相关库importnumpyasnpfromsklearn.datasetsimportload_irisfromsklearn.model_selectionimporttrain_test_split,cross_val_scorefromsklearn.clusterimportKMeansfromsklearn.metricsimportaccuracy_score,precision_score,recall_score,f1_scor......
  • 2024.12.5(周四)
    #导入必要的库importnumpyasnpfromsklearnimportdatasetsfromsklearn.model_selectionimporttrain_test_split,cross_val_score,StratifiedKFoldfromsklearn.naive_bayesimportGaussianNBfromsklearn.metricsimportaccuracy_score,precision_score,reca......
  • 2024.12.9(周一)
    importnumpyasnpimportpandasaspdfromsklearnimportdatasetsfromsklearn.model_selectionimporttrain_test_split,cross_val_score,StratifiedKFoldfromsklearn.ensembleimportRandomForestClassifierfromsklearn.metricsimportaccuracy_score,prec......
  • 11.25 周一日常
    11.25周一日常Q1.1200给定x,y,k,k次操作,每次操作:x++,若x可被y整除,x一直除以y。问最终x的值。(x,y,k≤1e9)Q2.1400给定一等差数列a,每次操作:令最大值=mex{a}。问是否可以将a变成0~n-1的排列和最小操作次数。(1e18)Q3.1600给定一数组和lim,设操作l,r:i:l->r,令s=0,s+=a[i];每一步如......
  • 2024.11.25(周一)
    用Java代码模拟实现课堂上的“银行账户”的实例,要求编写客户端测试代码模拟用户存款和取款,注意账户对象状态和行为的变化。实验要求:1.    画出对应的类图;2.    提交源代码;3.注意编程规范。  1、类图  2、源代码(1)GreenState.javapackagerjsj.no22;......
  • 2024.9.30(周一)
    <%@pagelanguage="java"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><!DOCTYPEhtml><html><head><title>产品批次</title><style>/*整体页面布局和样式*/......
  • 第二周9.2周一学习总结
    双指针洛谷题目A+B#include<bits/stdc++.h>#defineintlonglongconstintmaxn=2e5+10;inta[maxn];usingnamespacestd;signedmain() { intn,c; cin>>n>>c; for(inti=0;i<n;i++) { cin>>a[i]; } sort(a,a+n); intsum=0; f......
  • [每周一更]-(第111期):从零开始:如何在 CentOS 上源码编译安装 PHP 7.4
    文章目录系统信息:0、安装版本:1、下载/解压2、安装依赖3、配置autoconf4、配置参数5、编译和安装6、验证安装的插件6.1、配置php.ini6.2、配置opcache7、错误7.1Failedtoconnectto2a03:2880:f10e:83:face:b00c:0:25de:Networkisunreachable7.1.1禁用yum使用I......