你好啊我又又又来了
要准备usaco的铁铁们可以参考这个文章哦!

想刷好USACO——看这篇文章就够了_GeekAlice的博客-CSDN博客我最近是发现了一个很好用的网站https://blog.csdn.net/GeekAlice/article/details/122291933?spm=1001.2014.3001.5501
这次是银组的题解,

如果你想看铜组的话,传送门在这里:

USACO 1月 2021-2022 Contest Bronze 题解_GeekAlice的博客-CSDN博客USACO 2021-22 January Contest Bronze 完整版题解https://blog.csdn.net/GeekAlice/article/details/122798286?spm=1001.2014.3001.5502

:))

话不多说,上题解:


————————————————
版权声明:本文为CSDN博主「GeekAlice」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

题解:


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;public class SearchingForSoulmates {public static void main(String[] args) throws IOException {BufferedReader in = new BufferedReader(new InputStreamReader(System.in));StringBuilder out = new StringBuilder();for (int t = Integer.parseInt(in.readLine()); t > 0; t--) {StringTokenizer tokenizer = new StringTokenizer(in.readLine());long cow1 = Long.parseLong(tokenizer.nextToken());long cow2 = Long.parseLong(tokenizer.nextToken());long answer = Long.MAX_VALUE;for (int removed = 0; cow2 >> removed > 0; removed++) {long here = 0;long prefix = cow2 >> removed;long cow = cow1;while (cow > prefix) {if (cow % 2L == 1L) {cow++;here++;}cow /= 2L;here++;}here += prefix - cow;here += removed;here += Long.bitCount(cow2 & ((1L << removed) - 1L));answer = Math.min(answer, here);}out.append(answer).append('\n');}System.out.print(out);}
}

#include <bits/stdc++.h>
using namespace std;
int64_t ans = 0;
int N;
void add_contribution(const vector<int>& h) {vector<int> with_h(N+1);for (int i = 0; i < N; ++i) with_h[h[i]] = i;set<int> present;for (int cur_h = N; cur_h; --cur_h) {auto it = present.insert(with_h[cur_h]).first;if (next(it) != end(present)) ans += *next(it)-*it+1;}
}
void add_contribution_ll(const vector<int>& h) {vector<int> with_h(N+1);for (int i = 0; i < N; ++i) with_h[h[i]] = i;vector<int> pre(N), nex(N);for (int i = 0; i < N; ++i) {pre[i] = i-1;nex[i] = i+1;}for (int cur_h = 1; cur_h <= N; ++cur_h) {int pos = with_h[cur_h];int p = pre[pos], n = nex[pos];if (n != N) ans += n-pos+1, pre[n] = p;if (p != -1) nex[p] = n;}
}
void add_contribution_alt(const vector<int>& h) {stack<int> stk;for (int i = N-1; i >= 0; --i) {while (!stk.empty() && h[stk.top()] < h[i]) stk.pop();if (!stk.empty()) ans += stk.top()-i+1;stk.push(i);}
}int main() { cin >> N;vector<int> h(N); for (int& i: h) cin >> i;add_contribution(h);reverse(begin(h), end(h));add_contribution(h);cout << ans;
}

#include <bits/stdc++.h>
using namespace std;
struct edge {int cow;  int to;bool is_first;edge() {};edge(int cow, int to, bool is_first) : cow(cow), to(to), is_first(is_first) {};
};
vector<edge> adj[100001];
bool visited_cycle[100001];
bool visited[100001];
bool gets_cereal[100001];
int hungry_cows = 0;
queue<int> order;
int ignore_edge = -1,N,M,first_cereal = -1;  void find_cycle(int cur, int prev = -1) {visited_cycle[cur] = true; for (edge next : adj[cur]) {if (visited_cycle[next.to]) {if (first_cereal == -1 && next.to != prev) {if (next.is_first) {first_cereal = next.to; } else {first_cereal = cur;}ignore_edge = next.cow; order.push(next.cow);gets_cereal[next.cow] = true;}} else {find_cycle(next.to, cur);}}
}void dfs(int cur) {visited[cur] = true;for (edge next : adj[cur]) {if (!visited[next.to] && next.cow != ignore_edge) { gets_cereal[next.cow] = true;order.push(next.cow);dfs(next.to);}}
}int main() {cin >> N >> M;for (int i = 0; i < N; ++i) {int a, b;cin >> a >> b;adj[a].push_back(edge(i+1, b, false));adj[b].push_back(edge(i+1, a, true));}for (int i = 1; i <= M; ++i) {first_cereal = -1;ignore_edge = -1;if (!visited[i]) {find_cycle(i);if (first_cereal > 0) {dfs(first_cereal);} else {dfs(i);}}}for (int i = 1; i <= N; ++i) {if (!gets_cereal[i]) {++hungry_cows;order.push(i);} }cout << hungry_cows << endl;while (!order.empty()) {cout << order.front() << endl; order.pop();}return 0;
}

USACO 1月 2021-2022 January Contest Silver银组 题解相关推荐

  1. USACO 12月 2022-2023 December Contest Silver银组 题解

    版权声明:本文为CSDN博主「GeekAlice」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明. 目录 Problem 1. Barn Tree Problem 2 ...

  2. USACO 12月 2020-2021 December Contest Silver银组 题解

    Problem 1. Cowntagion Farmer John and his fellow farmers have been working nonstop to control the sp ...

  3. USACO 1月 2020-2021 January Contest Silver 题解

    Problem 1. Dance Mooves Farmer John's cows are showing off their new dance mooves! At first, all NN  ...

  4. USACO 2012 January Contest, Silver Division Solution

    T1是一道构图然后跑最短路的题. T2是一道裸的dp 然而我看了以后觉得爆搜是一定可以过掉的== 于是我先来一发二进制枚举,然后two points 维护答案.. T3是一道神题 首先要分类讨论,然后 ...

  5. USACO 2022 January Contest, Bronze

    Problem 1. Herdle 奶牛们发明了一种名为 Herdle 的新型解谜游戏,在牛界引起了轰动. 每天都会有一个新谜题发布供奶牛解决.游戏采用 3x3 方阵的形式表示农场的一块田地,田地的每 ...

  6. USACO 2022 January Contest, Bronze ——Problem 1. Herdle

    题目描述 奶牛们发明了一种名为 Herdle 的新型解谜游戏,在牛界引起了轰动. 每天都会有一个新谜题发布供奶牛解决.游戏采用 3x3 方阵的形式表示农场的一块田地,田地的每个方格都由特定品种的奶牛占 ...

  7. USACO 2018 January Contest Platinum A: Lifeguards 题解

    将所有的区间按左端点从小到大排序 我们处理那些被完全包含的区间,这些区间即使删除也不会使答案变坏 这样先删一波,如果发现这种小区间的个数多于k,就可以直接算答案了 否则我们要dp 设dp[i][j]为 ...

  8. KYOCERA Programming Contest 2021 (AtCoder Beginner Contest 200) A~E 题解

    ABC200/KYOCERA2021 A~E [A - Century](https://atcoder.jp/contests/abc200/tasks/abc200_a) 题目大意 输入格式 输出 ...

  9. Mynavi Programming Contest 2021 (AtCoder Beginner Contest 201) A~E 题解

    ABC201/Mynavi2021 A~E [A - Tiny Arithmetic Sequence](https://atcoder.jp/contests/abc201/tasks/abc201 ...

最新文章

  1. 用Remoting 实现一个文件传输组件
  2. 用Spotlight on windows 实时监控Windows服务器性能
  3. 百度云怎样提升下载速度
  4. “会”和 好”纯粹是两个概念
  5. 使用LightBDD轻松实现行为驱动开发
  6. 光端机怎样使用?光端机怎么和交换机连接?
  7. Shell:dos新建sh脚本在linux下执行报错“/bin/sh^M”
  8. [HDU5727]Necklace(二分图最大匹配,枚举)
  9. 苍狼敏捷软件开发团队建设指南-2-团队建设
  10. 强烈推荐!Python 这个宝藏库 re 正则匹配
  11. ping源码分析(超详细,多图,带背景分析)
  12. 谷歌小恐龙PHP代码,Chrome小恐龙前端修改代码代码总结
  13. 简单的爬虫(豆瓣250)
  14. 朴素贝叶斯——R语言
  15. APP案例分析--扇贝单词
  16. nacos 安装包下载 linux+windows
  17. 应聘华为各类工程师通信基础题库以及答案(转)
  18. 孙子兵法 三十六计(猫鼠版)
  19. GSoC2011 主要入选方向
  20. 在江南这四年(成长分享)

热门文章

  1. 开启火狐浏览器的账号密码导入功能
  2. 安恒西湖论剑周周练Reverse刮开有奖WP
  3. HTML+CSS之三角形和扇形的制作
  4. N71005-第五周
  5. 域名到期后多久释放?如何抢注到期域名?
  6. openai api 接口 列出模型信息
  7. 学校计算机机械设备管理制度,计算机教室设备管理制度.doc
  8. 哪些企业必须要注册35类商标?
  9. CCF CSP 集合竞价 (2014-12)
  10. Qgis 使用QuickOSM插件导入开源地图