当前位置: 首页 > news >正文

2025-11-23

CF

Problem - 1632C - Codeforces(枚举)(1600)

先加再按位或,一定最优

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;void solve()
{int a,b;cin >> a >> b;int ans = b-a;for (int i = a; i <= b;i++){int aa = i | b;ans = min(ans, i - a + 1 + aa - b);}for (int i = 0; i <= b - a;i++){int bb = b + i;int aa = a | bb;ans = min(ans, i + 1 + aa - bb);}cout << ans << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}

Problem - 1227D1 - Codeforces(排序)(1600虚高)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=105;
struct node{int num, id;
} a[N];bool cmp1(node a,node b){if(a.num!=b.num)return a.num > b.num;return a.id < b.id;
}bool cmp2(node a,node b){return a.id < b.id;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);int n;cin >> n;for (int i = 0; i < n; i++){cin >> a[i].num;a[i].id = i;}int m;cin >> m;while(m--){sort(a, a + n, cmp1);int k, pos;cin >> k >> pos;sort(a, a + k, cmp2);cout << a[pos-1].num << endl;}
}

构造专题(1300)

Problem - 1902C - Codeforces(构造)

#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod = 998244353;
const int N=2e5+10;
LL gcd(LL a,LL b){return b?gcd(b,a%b):a;
}
LL lcm(LL a,LL b){return a/gcd(a,b)*b;
}
LL a[N];void solve()
{map<int,int> mp;int n;cin >> n;for (int i = 0; i < n;i++){cin >> a[i];mp[a[i]] = 1;}if(n==1){cout << 1 << endl;return;}sort(a, a + n);LL g = a[1] - a[0];for (int i = 2; i < n;i++){g = gcd(g, a[i] - a[i - 1]);}LL cnt = 0;for (int i = 0; i < n;i++){cnt += (a[n - 1] - a[i]) / g;}LL k = 1;while(1){//妙if(mp[a[n-1]-k*g]==0)break;k += 1;}LL ans = 1e18;//注意ans要定义为局部变量ans = min(ans, cnt + k);cout << ans << endl;
}int main()
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);int T;cin >> T;while (T--){solve();}
}
http://www.gsyq.cn/news/58437.html

相关文章:

  • 2025软件工程L班
  • 使用Ansible批量安装JDK
  • static 静态变量
  • 2025-09-10-Wed-T-Milvus
  • 2025.11.23
  • java linux服务器
  • 贪心做题记录-2
  • 2025 年上海金蝶软件定制开发代理商推荐榜出炉
  • 【开发者导航】全自动 AI 视频创作与发布工具:LuoGen-agent - 教程
  • 截图工具
  • 人工智能之数据分析 numpy:第十二章 数据持久化
  • anchor
  • 2025 年上海最靠谱的金蝶代理商:聚焦官方授权与深度适配,这家最高级铂金伙伴值得选
  • 单克隆抗体在药物研发和治疗领域的应用前景
  • 2025 年上海金蝶软件代理商推荐榜:上海宝蝶信息科技有限公司全行业覆盖、金蝶最高级铂金伙伴
  • Jetson Orin Nano super -3 NVIDIA Jetson 平台的技术架构和NVIDIA JetPack
  • 学习DA
  • 候选区域
  • 数据结构理论知识 - 指南
  • 大盘风险控制策略分析报告 - 2025年11月21日
  • 前端八股文-高频面试题 - 教程
  • 2024软工K班结对编程任务
  • 实用指南:各种各样的Self-attention学习上(第二十周周报)
  • 20251123 之所思 - 人生如梦
  • 人工智能之数据分析 numpy:第十章 副本视图
  • Node.js 端的接口签名处理
  • 20232402 2025-2026-1 《网络与系统攻防技术》实验六实验报告
  • the success of Japan
  • 赫尔默特变化 A=0的情况
  • 20232411 2024-2025-1 《网络与系统攻防技术》实验六实验报告