ICode9

精准搜索请尝试: 精确搜索
  • 1406B - Maximum Product2022-06-18 13:04:13

    贪心: 先将所有数选出最小和最大的5个数,再按绝对值大小枚举选数字 #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const int N = 100010; int n; int a[N],b[N]; int main () { int T; cin >> T; while (T--) { cin >> n; for (in

  • 1097B - Petr and a Combination Lock2022-06-18 13:01:28

    位运算: 用在\([0,2^n]\)的每一个数来枚举所有情况,如果\(i >> j \& 1 == 1\),那么第j个数就要加上,否则要减去 #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int N = 20; int n; int a[N]; int main () { cin >> n; for

  • B - Pleasant Pairs2022-06-18 12:35:07

    因为是 a[i] * a[j] ,然后这里是根据a[i]来找a[j],可以知道i+j一定是a[i]的倍数,i是不变的,所以j的增加量一定是a[i]的倍数。其中j = a[i]-i对应的是a[j] = 1,j = a[i]对应的是a[j] = 2,以此类推。 #include <iostream> using namespace std; typedef long long LL; const int N = 10001

  • A. XXXXX2022-06-18 09:36:32

    当总和不是x的倍数时,答案就是n;当数组里所有数是x的倍数时,答案是-1;否则从两侧一直往中间收缩,答案就是max (n-l,r-1) #include <iostream> using namespace std; const int N = 100010; int n,x,sum; int a[N]; int main () { int T; cin >> T; while (T--) { sum = 0; bool

  • TZOJ 5374: C++实验:STL之全排列2022-06-17 17:37:40

    描述     使用STL中的next_permutation函数输出一个序列的全排列。 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码。     C++ int main() { vector<int> vec; int n, x; cin>>n; while(n--) { cin>>x; vec.push_back(x);

  • [AcWing 1017] 怪盗基德的滑翔翼2022-06-16 22:03:47

    点击查看代码 #include<iostream> using namespace std; const int N = 110; int k, n; int a[N], f[N]; int main() { cin >> k; while (k --) { cin >> n; for (int i = 1; i <= n; i ++) cin >> a[i]; int res = 0; for (int i = 1; i

  • 牛客_设计带有setAll功能的哈希表2022-06-16 15:04:29

    思路: 使用“版本号”记录每个key对应的最新的value值。 实现: 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main(){ 4 //freopen("in.txt", "r", stdin); 5 int t;cin>>t; 6 int cnt=0;int val=-1; 7 unordered_map<int,pa

  • cf1574 D. The Strongest Build2022-06-16 13:03:18

    题意: 有 \(n\) 组数,在每组数中选一个数,最大化总和。有 \(m\) 个选数方案是被 ban 的 \(n\le 10,m\le 1e5\) 思路: 这是个经典老题了,这里主要提示一下复杂度并记录一种更好的写法。 常规 bfs 做法: bfs起点:每组都选最大的 若大根堆顶被 ban,把堆顶修改一维得到 \(n\) 个新备选方案入堆

  • NC204859 组队2022-06-15 19:04:15

    NC204859 组队 题目 题目描述 你的团队中有 \(n\) 个人,每个人有一个能力值 \(a_i\),现在需要选择若干个人组成一个团队去参加比赛,由于比赛的规则限制,一个团队里面任意两个人能力的差值必须要小于等于 \(k\) ,为了让更多的人有参加比赛的机会,你最多能选择多少个人参加比赛? 输入描述

  • ACM集训题(1)2022-06-15 19:02:17

    title: acm训练习题 author: Sun-Wind date: June 15,2022 A 此题较为简单,主要考察了setprecision函数来输出小数 考察知识点:语法 #include<bits/stdc++.h> #include<iomanip> using namespace std; #define int long long #define endl '\n' signed main(){ ios::sync_wit

  • 【线性dp】AcWing898.数字三角形2022-06-14 22:33:14

    AcWing898.数字三角形 题解 自底向上 #include <iostream> using namespace std; const int N = 510; int f[N][N]; int main() { int n; cin >> n; for(int i = 1; i <= n; ++i) for(int j = 1; j <= i; ++j) cin >> f[i

  • 比试2022-06-13 21:03:38

    比试 这道题用正常的方法一定会超时。 题目要求的是交换数列中所有的x和y,所以我们可以建立一个数组p[x] = y, p[y] = x,输出的时候输出对应的数组值即可 #include <iostream> using namespace std; const int N = 1e5 + 10; int s[N], n, m; int p[20]; int main() { cin.tie(

  • cf468 B. Two Sets2022-06-12 18:32:19

    题意: 给定 \(n\) 个两两不同的正整数,问能否把它们不重不漏地分为两个集合 \(A,B\)。要求: \(x\in A\implies a-x\in A\) \(x\in B\implies b-x\in B\) 思路: 法一:很傻很暴力 先假定所有数都属于 \(A\) 检查所有数,对某数 \(x\),若 \(a-x\notin A\),则把 \(x\) 推入待处理队列 \(q\) 检

  • atcoder beginner contest 2552022-06-12 12:01:23

    A - You should output ARC, though this is ABC. 代码: #include <bits/stdc++.h> #define int long long int _ = 0, Case = 1; using namespace std; #define all(v) begin(v),end(v) #define nline '\n' int a[3][3]; void solve(int Case) { int x,

  • Codeforces Round #798 (Div. 2)2022-06-11 19:32:18

    A. Lex String 题意 给定长度为\(n\)的串\(a\)和长度为\(m\)的串\(b\),保证没有字符同时出现在两个串中。 有一个初始为空的串\(c\),支持以下两种操作: 从\(a\)中选一个字符,将其从\(a\)中删除,然后加到\(c\)的末尾。 从\(b\)中选一个字符,将其从\(b\)中删除,然后加到\(c\)的末尾。 还

  • 牛客-牛客练习赛100B 小红的子序列2022-06-11 00:33:34

    小红的子序列 今日无事,勾栏.. 今天心血来潮打了一下牛客,发现了一道有趣的题 dp 大概就是把 颜色 和 奇偶 分成两个状态:当前位置是否是奇数,当前颜色是否是红色,类似于状态压缩一样压一下,然后 dp 不断维护最大值就好 状态转移就是从将当前状态 取反 转移过来就好 #include <iostream>

  • 【快速幂】AcWing875.快速幂——模板题2022-06-09 21:34:08

    AcWing875.快速幂 题解 #include <iostream> using namespace std; typedef long long LL; int main() { int n, a, b, p; cin >> n; while(n -- ) { int res = 1; cin >> a >> b >> p; while(b)

  • 2022.6.92022-06-09 13:02:05

    Codeforces Round #797 (Div. 3) A - Print a Pedestal #include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; const int N=1e5+10,INF=1e9; int main() { ios::sync_with_stdio(false); cin.tie(0); int

  • Codeforces Round #797 (Div. 3) A-F2022-06-08 13:02:34

    Codeforces Round #797 (Div. 3) A-F https://codeforces.com/contest/1690 A. Print a Pedestal (Codeforces logo?) 就是一个codeforces(颁奖台)的形状;中间的 最高,左边第二,右边第三 然后要使得中间的尽可能小,那么就按照等差数列来构造处理。 最理想情况下是 \(x-1, x, x-2\),且满足

  • Codeforces Round #797 (Div. 3) D, E, F, G题题解2022-06-08 10:02:14

    Codeforces题解汇总 Round #797 div3 D. Black and White Stripe 固定长度最大子段和, 简单只贴代码了 Solution #include<bits/stdc++.h> typedef long long ll; typedef std::pair<int, int> PII; typedef std::pair<ll, ll> PLL; typedef unsigned long long ull; typedef

  • 【欧拉函数】AcWing873. 欧拉函数——欧拉函数的证明与代码2022-06-07 21:32:48

    AcWing873.欧拉函数 证明与题解 #include <iostream> using namespace std; int phi(int x) { int res = x; for(int i = 2; i <= x / i; ++i) { if(x % i == 0) { res = res / i * (i - 1); //先除后乘防止爆int while

  • 【P3373 【模板】线段树 2】(2022.06.04)pj2022-06-04 22:33:08

    只需扣(线段树)模板2就可。。 线段树模板2: #include<iostream> #include<fstream> #include<cstring> #include<string> #include<algorithm> #include<cstdio> #include<cmath> #include<queue> #include<stack> #define ll long lon

  • (树形dp)Spring tree2022-06-04 22:32:09

    题目链接 Spring tree 题目概述 给定n个铁球,重量为wi,再给定n - 1条弹簧(可变的边权)所链接的两端,每个位置上的铁球可以相互交换。弹簧的长度为每个节点的子树边权和+1。问从根节点(1节点)开始的最大深度。 输入 #1 4 1 2 3 4 1 2 2 3 3 4 输出 #1 23 样例说明 In the test case, kee

  • AcWing 1019. 庆功会(多重背包)2022-06-04 17:31:30

    题目链接 题目描述 为了庆贺班级在校运动会上取得全校第一名成绩,班主任决定开一场庆功会,为此拨款购买奖品犒劳运动员。 期望拨款金额能购买最大价值的奖品,可以补充他们的精力和体力。 题目模型 多重背包简单应用 题目代码 #include <iostream> using namespace std; const i

  • 电影2022-06-01 00:33:27

    1.电影 链接 题目描述 有n个科学家,编号从1~10^9,我们要为他们准备电影,如果能听懂电影的语音最开心,能看懂电影的字幕比较开心,听不懂以及看不懂的不开心,我们要找出最开心的观看电影编号,没有则任意输出即可。 第一行输入一个整数 n,代表科学家的数量。 第二行输入 n 个整数 a1,a2…an,其

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有