ICode9

精准搜索请尝试: 精确搜索
  • 情侣名2022-08-23 15:30:08

                    解析: 主要是char  string 与 int 的转换 用map即可 构造出关系矩阵就好了 #include <bits/stdc++.h> using namespace std; map<string, int> index; map<string, int> hashmap; map<int, string> unhashmap; map<string, int> vis; vector<stri

  • 推荐系统2022-08-23 14:02:48

    https://www.acwing.com/problem/content/1624/ 写法1 #include <iostream> #include <cstring> #include <algorithm> #include <set> using namespace std; struct node { int value, cnt; bool operator < (const node& t) const

  • leetcode68-文本左右对齐2022-08-23 10:03:19

    文本左右对齐 模拟 先对所有字符串进行一次遍历,保证每个字符串之间有一个空格,然后对字符串分组,确定字符串的位置。 然后对每一组的字符串分配空格:遍历这一组的字符串长度,计算出剩余的空格总数,并根据空格总数分配出固有的空格和多出来的空格数量,依次添加。 注意:最后一行字符之间

  • 社会集群2022-08-23 00:03:39

    https://www.acwing.com/problem/content/description/1599/ #include <iostream> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int N = 1010; int n; vector<int> hobby[N]; int p[N]; int cn

  • 谷歌的招聘2022-08-22 20:02:09

    https://www.acwing.com/problem/content/1648/ 思路: 如果单纯的用试除法去做,可能会超时,我们在这里先弄出来根号内的所有质数,然后用质数来做。 #include <iostream> #include <cstring> using namespace std; const int N = 1010, M = 40000; int n, k; bool st[M]; int prime

  • acwing第65场周赛2022-08-21 22:01:29

    1.最大价值 原题链接:https://www.acwing.com/problem/content/4606/ 思路 经典双指针 代码: #include<iostream> #include<algorithm> #include<cstring> using namespace std; int main() { int n; cin >> n; while(n --) { int slen;

  • 哈密顿回路2022-08-21 20:32:49

    https://www.acwing.com/problem/content/description/1617/ 思路: 需要满足:1. 第一个点和最后一个点相同,这样才能形成回路。 2.要有恰好有n+1个点,因为哈密顿回路本身就要求经过图中每个顶点。 3. 且每个顶点都必须遍历到。 4. 每两个点之间都要有边相连接。 #include <iostream>

  • 欧拉路径2022-08-21 20:30:08

    https://www.acwing.com/problem/content/1621/ //欧拉图:连通 && 所有点的度数为偶 //半欧拉图:连通 && 只有2个点的度数为奇 其余度数为偶 //非欧拉图:else #include<iostream> #include<algorithm> #include<cstring> using namespace std; const int N=550; bool g[N][N],

  • [NOIP1998 普及组] 三连击2022-08-21 20:04:11

    生成九位一到九的全排列,按题目分割、过滤 #include<iostream> #include<vector> #include<algorithm> bool vis[20]; int queue[50]; int answers[500]; int cnt=0; void search(int x) { for(int i=1;i<=9;i++)//每位数由1到9中的一个 { if(!vis[i]) {

  • 团伙头目2022-08-21 20:02:07

    https://www.acwing.com/problem/content/1520/ 思路: 先找到在一个团伙中的人(可以用树的dfs来做,也可以用并查集来做),然后遍历每一个合法的集合,找到里面的头目。 并查集的做法 #include <iostream> #include <unordered_map> #include <cstring> #include <vector> #include <algor

  • 219. 存在重复元素 II2022-08-21 19:00:48

      思路 难度简单506收藏分享切换为英文接收动态反馈 给你一个整数数组 nums 和一个整数 k ,判断数组中是否存在两个 不同的索引 i 和 j ,满足 nums[i] == nums[j] 且 abs(i - j) <= k 。如果存在,返回 true ;否则,返回 false 。   示例 1: 输入:nums = [1,2,3,1

  • 2020年9月乙组 最大圆弧2022-08-21 15:02:04

    首先,如果将题目的“圆环”改成“数组”,相信大家都会做,就是如下 int sum=0,maxn=0;//sum更新最大值 for(int i = 1;i <= n;i++){ scanf("%d",&a); if(sum < 0)sum = 0;//当sum小于零时,不如啥都不选 sum += a; maxn = max(maxn,sum); } printf("%d\n",maxn); 但是此题是一个环

  • [Ynoi2015] 盼君勿忘2022-08-21 02:02:21

    题传 世纪诈骗题 首先,所有子序列分别去重的和的意思是什么? 令可重集 \(S\) 为序列 \(a_l, a_{l+1}\dots a_r\) 的所有子序契合。 假设我们有一个序列 \(T\),对 \(T\) 去重后变为 \(T'\),令 \(f(T)=\sum_{x \in T'} x\),则题目所求为 \(\sum_{T \in S} f(T)\)。 显然我们不能把所有的

  • 2022/8/20 总结2022-08-20 14:30:55

    A.P4398 [JSOI2008]Blue Mary的战役地图 考场写了个暴力,我还以为要挂了,结果这题暴力可过; Solution 本来想写 \(\mathtt{O(n^6)}\) 的暴力,但感觉可能过不了,所以加了亿点小优化; 我把第一张地图(记为 \(a\))里的所有数字进行了离散化,开了一个 \(\mathtt{vector}\) 来存每个值在第

  • 牛客小白月赛55 A-E2022-08-20 01:32:48

    牛客小白月赛55 A-E https://ac.nowcoder.com/acm/contest/38630 F待补 解析啥的睡醒再补,先放个代码 A - 至至子的等差中项 #include <bits/stdc++.h> using namespace std; int main () { int a, b; cin >> a >> b; cout << 2*b-a; } B - 至至子的按位与 #includ

  • 算法竞赛进阶指南 0x65 负环与差分约数2022-08-20 00:32:52

    这里与最短路密切相关 可以使用spfa,利用spfa的原理(cnt数组),如果发现一个点是通过了超过n-1条边更新而来,那么就说明存在负环 AcWing361. 观光奶牛 给定一张 L 个点、P 条边的有向图,每个点都有一个权值 f[i],每条边都有一个权值 t[i]。 求图中的一个环,使“环上各点的权值之和”除以“

  • 解题报告——P3477 [POI2008]PER-Permutation2022-08-19 09:33:33

    这道题如果不是任意模数的话还是比较平凡的( 这道题的式子其实很好推,根据康托展开的思路,一位一位考虑,只不过是多重集,可能有重复情况,排除即可,每一位的式子为: \[ans_i=\dfrac{(n-i)!}{\prod cnt_j}\times\sum^n_{k=i+1}[ a_k<a_i] \](\(cnt_j\) 为 \(i-n\) 之间 \(j\) 的个数,\(a_i\)

  • 暑假集训62022-08-19 07:00:08

    前两题只会打暴力,本来以为又要垫底了,结果还可以? A. 接力比赛 确实是背包,排序后每次跑上界为\(\sum w_i\),然后刚刚好卡过?? 随机数据跑的还是挺快的 code #include<cstring> #include<cstdio> #include<algorithm> #include<vector> #include<queue> #include<iostream> #include<s

  • 2492. HH的项链2022-08-19 02:03:24

    题目链接 2492. HH的项链 HH 有一串由各种漂亮的贝壳组成的项链。 HH 相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义。 HH 不断地收集新的贝壳,因此他的项链变得越来越长。 有一天,他突然提出了一个问题:某一段贝壳中,包含了多少种不同的贝壳?

  • SPOJ-CAPCITY Capital City2022-08-18 20:33:11

    Capital City tarjan 缩点 缩点之后,找到 DAG 图中唯一一个出度为 \(0\) 的点,如果有多个,说明不成立 #include <iostream> #include <cstdio> #include <algorithm> #include <stack> #include <queue> #include <vector> using namespace std; const int maxn = 2e

  • [CF1450F] The Struggling Contestant 题解2022-08-18 05:00:08

    \(\mathtt{Link}\) CF1450F The Struggling Contestant - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) \(\mathtt{Description}\) \(T\) 组数据。 一共有 \(n\) 道题,题号从 \(1\) 到 \(n\),其中题号为 \(i\) 的题有一个标签 \(a_i\)。 需要确定一个做完 \(n\) 道题的顺序,使得所做

  • [AcWing 166] 数独2022-08-18 00:30:56

    DFS + 剪枝 + 位运算优化 点击查看代码 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N = 9, M = 1 << N; int ones[M]; // ones[i]表示i的二进制数中1的个数 int map2[M]; // map2[i]表示log_2(i) int row[N], col[N], cell[3][3]; /

  • 区间合并 左端点1右端点-1的等待cnt=0的情况2022-08-18 00:30:40

    牛客第一题https://ac.nowcoder.com/acm/contest/33186/A signed main(){ // ios::sync_with_stdio(false); // cin.tie(0),cout.tie(0); int n; cin>>n; for(int i=0;i<n;i++){ int a,b;cin>>a>>b; v.push_back({a-b,1}); v.push_back({a+b,-1});

  • YbtOJ 「图论」第2章 最小生成树2022-08-17 21:00:24

    为什么区间 dp 又咕咕咕了QAQ 于是随机抽取了一个幸运章节来做。 目前处于半摆烂状态。 例题1.繁忙都市 板子。写了下以前几乎没写过的堆优化 Prim。 code #include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second using namespace std; const i

  • [复习#2022-8-17]基础搜索(1)2022-08-17 18:33:52

    DFS (来自OIWIKI)在搜索算法中,该词常常指利用递归函数方便地实现暴力枚举的算法 那我们可以尝试一下: 先写出递归: int xxx(int x,......) { if(边界到了) { ...... } else return xxx(x+1,......); } 再把else部分改成暴力 int xxx(int x,......) { if(

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

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

ICode9版权所有