目录

  • A、Remove Smallest(模拟)
  • B、Gifts Fixing(模拟)
  • C、Boats Competition(暴力枚举)
  • D、Binary String To Subsequences(字符串,类并查集)
  • E1、Weights Division (easy version)(贪心、树上dfs)
  • F、Yet Another Segments Subset(区间DP)

A、Remove Smallest(模拟)

#include<cstdio>
#include<algorithm>using namespace std;
const int N = 50007;int a[N];
int n, m, t;
int main()
{scanf("%d", &t);while(t -- ){scanf("%d", &n);bool flag = 0;for(int i = 1; i <= n; ++ i){scanf("%d", &a[i]);}sort(a + 1, a + 1 + n);for(int i = 1; i < n; ++ i){if(a[i + 1] - a[i] > 1){flag = 1;break;}}if(!flag)puts("YES");else puts("NO");}return 0;
}

B、Gifts Fixing(模拟)

![在这里

#include<iostream>
#include<algorithm>
#include<cstring>
typedef long long ll;
using namespace std;
const int N = 50007, INF = 0x3f3f3f3f;
int n, m, t;
int a[N], b[N];
int mina, minb;
int main(){cin >> t;while(t -- ){cin >> n;mina = INF, minb = INF;for(int i = 1; i <= n; ++ i){cin >> a[i], mina = min(mina, a[i]);}for(int i = 1; i <= n; ++ i)cin >> b[i], minb = min(minb, b[i]);ll ans = 0;for(int i = 1; i <= n; ++ i){ans += max(a[i] - mina, b[i] - minb);}cout << ans << endl;}return 0;
}

C、Boats Competition(暴力枚举)


直接暴力枚举结果s即可。

#include<algorithm>
#include<cstring>
#include<cstdio>
#include<iostream>
using namespace std;
const int N = 5007;
int n, m, t;
int a[N];
int main(){cin >> t;while(t -- ){cin >> n;for(int i = 1; i <= n; ++ i){scanf("%d", &a[i]);}sort(a + 1, a + 1 + n);int res = 0;for(int s = 2; s <= 2 * n; ++ s){int l = 1, r = n;int ans = 0;while(l < r){if(a[l] + a[r] > s)r -- ;else if(a[l] + a[r] < s)l ++ ;else ans ++ , l ++ , r -- ;}res = max(res, ans);}cout << res <<endl;}return 0;
}

D、Binary String To Subsequences(字符串,类并查集)

#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>using namespace std;const int N = 500007;int pre[N][2], a[N];
int last[2];
int ans[N];
string s;
int n, m;
int t;
int num[N];
bool vis[N];
int cnt;
int find(int x, int val)
{if(!x)return 0;if(!vis[x]){vis[x] = 1;return x;}return pre[x][val] = find(pre[x][val], val);
}int main(){scanf("%d", &t);while(t -- ){memset(vis, 0, sizeof vis);memset(num, 0, sizeof num);scanf("%d", &n);int res = n;cnt = 0;cin >> s;last[0] = last[1] = 0;for(int i = 1; i <= n; ++ i){a[i] = s[i - 1] - '0';pre[i][a[i] ^ 1] = last[a[i] ^ 1];pre[i][a[i]] = last[a[i]];last[a[i]] = i;ans[i] = i;}for(int i = 1; i <= n; ++ i){int point = find(pre[i][a[i] ^ 1], a[i] ^ 1);if(point){res -- ;ans[i] = ans[point];}}printf("%d\n", res);for(int i = 1; i <= n; ++ i){if(!num[ans[i]])num[ans[i]] = ++ cnt;printf("%d ", num[ans[i]]);}puts("");}return 0;
}

E1、Weights Division (easy version)(贪心、树上dfs)

全部改成long long就A了

#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<queue>#define int long long
typedef long long ll;
using namespace std;
const int N = 500007, M = 5000007;int n, m;
int head[N], nex[M], ver[M], edge[M], tot;
struct node{int val, son;bool operator<(const node &t)const {return (val - val / 2) * son < (t.val - t.val / 2) * t.son;}
};
priority_queue<node>heap;ll S, sum;
int t;
bool vis[N];void add(int x, int y, int z){ver[tot] = y;edge[tot] = z;nex[tot] = head[x];head[x] = tot ++ ;
}int dfs(int x, int fa){int cnt = 0;//儿子个数for(int i = head[x]; ~i;i = nex[i]){int y = ver[i], z = edge[i];if(y != fa){int num = dfs(y, x);heap.push({z, num});sum += z * num * 1ll;cnt += num;}}return max(cnt, 1ll);//可能是叶子节点
}signed main(){scanf("%lld", &t);while(t -- ){scanf("%lld%lld", &n, &S);memset(head, -1, sizeof head);memset(vis, 0, sizeof vis);sum = 0;tot = 0;while(heap.size())heap.pop();for(int i = 1, x, y, z; i <= n - 1; ++ i){scanf("%lld%lld%lld", &x, &y, &z);add(x, y, z), add(y, x ,z);}//int xx = 0;dfs(1, 0);ll ans = 0;while(sum > S){auto x = heap.top();heap.pop();//cout << x.val << "ok" <<x.son <<endl;sum -= (x.val - x.val / 2) * x.son *1ll;x.val /= 2;heap.push(x);ans ++ ;//cout << sum << endl;}//cout << xx ++ << endl;printf("%lld\n", ans);}return 0;
}

F、Yet Another Segments Subset(区间DP)

Codeforces Round #661 (Div. 3)题解相关推荐

  1. Codeforces Round #514 (Div. 2)题解

    Codeforces Round #514 (Div. 2)题解 A 喵,直接模拟. B 枚举所有盖章时的,合法的,左上角的位置.能盖的话就盖一下.最后check一下图案是否相等即可 C 一轮一轮的扔 ...

  2. Codeforces Round #182 (Div. 1)题解【ABCD】

    Codeforces Round #182 (Div. 1)题解 A题:Yaroslav and Sequence1 题意: 给你\(2*n+1\)个元素,你每次可以进行无数种操作,每次操作必须选择其 ...

  3. 【算法题解】Codeforces Round #817 (Div. 4)题解

    文章目录 Codeforces Round #817 (Div. 4)题解 A. Spell Check B. Colourblindness C. Word Game D. Line E. Coun ...

  4. Codeforces Round #747 (Div. 2)题解

    Codeforces Round #747 (Div. 2)题解 (本博客将持续更新以后每场CF div2的题解,喜欢ACM.OI的小伙伴记得点个关注哟) 昨天夜晚刷网络流刷入迷了,渐渐就忘记了我还要 ...

  5. Codeforces Round #789 (Div. 2)题解

    Codeforces Round #789 (Div. 2)题解 A. Tokitsukaze and All Zero Sequence 原题链接 算法标签 贪心 排序 思路 情况一:数组存在零 → ...

  6. Codeforces Round #748 (Div. 3) 题解 完整A~G

    Codeforces Round #748 (Div. 3) 题解 A. Elections 题意 已知竞选中三个候选人的当前得票数 a , b , c a,b,c a,b,c,现在可以增加任何一个人 ...

  7. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

  8. Codeforces Round #734 (Div. 3) 题解

    Hello大家好,今天给大家带来的是 Codeforces Round #734 (Div. 3) 的全题目讲解. 本文链接:https://www.lanqiao.cn/questions/2040 ...

  9. Codeforces Round #462 (Div. 2)题解

    Codeforces Round #462 (Div. 2) B题--我固执的认为1e18是18位数,导致被hack,花了20分钟才检查出这个错误,很僵硬 Codeforces 934C 题意 给定一 ...

最新文章

  1. mysql 触发器 实例_mysql的触发器-含案例-含效果 | 时刻需
  2. Win7下运行VC程序UAC权限问题
  3. Java格式化日期和时间模式占位符
  4. linux卸载已安装的java_Linux 中如何卸载已安装的软件(转载)
  5. 前端学习(3294):effect hook
  6. python输出国际象棋棋盘_python输出国际象棋棋盘的实例分享
  7. 服务端指南 数据存储篇 | 聊聊 Redis 使用场景(转)
  8. 使用二分查询数组中的某一个元素,简单示例,详细注解
  9. 勤哲web配置教程_勤哲excel服务器安装与使用
  10. vscode 下载加速方法
  11. 淘宝抢拍器 chrome extension实现
  12. java刷票脚本_我来分享一段自己写的刷票脚本 Version 1.0
  13. 花式方法解决不同vlan的主机互通
  14. 简单易懂使用DDOS攻击
  15. 使用MNE工具包处理脑电数据(1)基础处理总览(EEG、MEG、ERP研究)
  16. SpringBoot项目运行时出现A cookie header was received警告问题
  17. Exoplayer的详细使用UI篇
  18. 在校生学习云计算HCIE难吗?好就业吗?
  19. yandex注册验证码怎么填_注册163邮箱格式怎么填?163电子邮件注册格式
  20. android数字转汉字大写字母,将数字金额转成汉字大写的

热门文章

  1. 一种全自动的牙齿CBCT三维个体识别和分割方法
  2. 搭建hbase1.2.5完全分布式集群
  3. (转)Python rsa 签名与验证 sign and verify
  4. PHP CURL方法,GETPOST请求。
  5. 域名跳转301-LAMP环境搭建
  6. asp.net mvc发送邮件
  7. OpenvSwitch代码分析之bridge和port
  8. LeetCode——Rotate Image(二维数组顺时针旋转90度)
  9. 搞死了 报错【libc-client.a: could not read symbols: ...
  10. pcre安装_Nginx学习_第一期_安装及安装问题解决