ABC362
A
link

判断即可。。。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int r,g,b;
string c;
signed main(){
cin >> r >> g >> b >> c;
if(c == "Red") cout << min(g,b);
else if(c == "Blue") cout << min(r,g);
else cout << min(r,b);
return 0;
}
B
link

根据距离公式算三边距离,再根据勾股定理计算是否为\(RT△\)
注意\(double\)型不能直接判断相等,要判断差的绝对值小于某一个很小的数。
点击查看代码
#include<bits/stdc++.h>
using namespace std;
int xa,ya,xb,yb,xc,yc;
double dis(int x,int y,int l,int r){
return sqrt(1.0*(x-l)*(x-l)+1.0*(y-r)*(y-r));
}
signed main(){
cin >> xa >> ya >> xb >> yb >> xc >> yc;
double a[3] = {dis(xa,ya,xb,yb),
dis(xa,ya,xc,yc),dis(xb,yb,xc,yc)};
sort(a,a+3);
double t = a[0]*a[0]+a[1]*a[1];
double tt = a[2]*a[2];
if(abs(t-tt) < 1e-6) cout << "Yes";
else cout << "No";
return 0;
}
C
link

首先,判断一下是否可能:把所有的\(l_i\)和\(r_i\)分别相加,得到两个数\(R\)和\(L\)。
如果\(L\)到\(R\)包括\(0\)即有解。因为所有数之和最小为\(L\),最大为\(R\),所以\(L\)到\(R\)包括\(0\)即有解。
那么怎么求解呢?
我们先让所有的\(a_i\)等于\(l_i\),这时所有数的和小于\(0\)。接下来,我们从\(1\)开始遍历,如果当前所有数的和仍不是\(0\)(小于\(0\)),则让\(a_i\)变大,如果可以变到\(r_i\)则变到\(r_i\),否则变大当前所有数的和与\(0\)的差。
点击查看代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,suml,sumr;
int l[200005],r[200005];
int a[200005];
signed main(){
cin >> n;
for(int i = 1;i <= n;++ i){
cin >> l[i] >> r[i];
suml += l[i];
sumr += r[i];
a[i] = l[i];
}
if(suml <= 0&&sumr >= 0) cout << "Yes\n";
else{
cout << "No";
return 0;
}
int tmp = -1*suml;
for(int i = 1;i <= n;++ i){
if(tmp > r[i]-l[i]){
a[i] = r[i];
tmp -= r[i]-l[i];
}
else{
a[i] += tmp;
break;
}
}
for(int i = 1;i <= n;++ i)
cout << a[i] << " ";
return 0;
}
D
link

这个题就是最短路。
对于一条边,将终点的点权加到边权里去,跑最短路即可,最后把起点的点权加上。
点击查看代码
#include<bits/stdc++.h>
#define pii pair<int,int>
#define int long long
using namespace std;
int n,m;
int a[200005];
vector<pair<int,int> > ed[200005];
int ds[200005];
const int inf = 1e18;
bool vs[200005];
void dijkstra(int s){
for(int i = 1;i <= n;++ i)
ds[i] = inf;
ds[s] = a[s];
priority_queue<pii,vector<pii>,greater<pii> >q;
q.push({ds[s],s});
while(!q.empty()){
int t = q.top().second;q.pop();
if(vs[t]) continue;
vs[t] = 1;
for(int i = 0;i < ed[t].size();++ i){
int j = ed[t][i].first,
w = ed[t][i].second;
if(ds[j] > ds[t]+w){
ds[j] = ds[t]+w;
q.push({ds[j],j});
}
}
}
}
signed main(){
cin >> n >> m;
for(int i = 1;i <= n;++ i)
cin >> a[i];
for(int i = 1;i <= m;++ i){
int u,v,w;
cin >> u >> v >> w;
ed[u].push_back({v,w+a[v]});
ed[v].push_back({u,w+a[u]});
}
dijkstra(1);
for(int i = 2;i <= n;++ i)
cout << ds[i] << " ";
return 0;
}
随机推荐
- wpf 动画显示隐藏_[UWP]用Win2D和CompositionAPI实现文字的发光效果,并制作动画
weixin_39880899于 2020-12-11 09:26:23 发布 阅读量521 收藏 点赞数 文章标签: wpf 动画显示隐藏 1. 成果 献祭了周末的晚上,成功召唤出了上面的番茄钟 ...
- Windows库链接报错
问题回溯 今天拿到别人已经编译好的库,发现在链接的时候出现了报错 [9/9 12.7/sec] Linking CXX shared module bin\plugins\AsensingPlugin ...
- 2023 Hive 面试大纲
先说一些废话 总结一下Hive面试宝典中的要点,方便读者快速过一遍Hive面试所需要的知识点. 本文请搭配 Hive面试宝典 来食用更美味哟 ┗( ▔, ▔ )┛ 方便自己系统性回忆,根据*的数量来标 ...
- 滚动条小实验 BOM时间操作
<div class="top">我是吸顶div</div> <p class="back">返回顶部</ ...
- JavaScript中如何终止forEach循环&跳出for(双层)循环?
在JavaScript中,forEach方法是用于遍历数组的,通常没有直接终止循环的机制.然而,我们可以使用一些技巧来模拟终止forEach循环.以下是几种常见的方法 1.使用return语句:在fo ...
- 泛型模板化设计DEMO
泛型模板化设计DEMO 1. 定义Result泛型类 package com.example.core.mydemo.java.fanxing; public class Result<T> ...
- IT运维全面数字化|芯片设计行业领跑打造运维流程闭环
在当今数字化转型的浪潮中,科技行业正经历着前所未有的变革.随着5G.人工智能.物联网等新兴技术的快速发展,企业对于高效.智能的运营模式的需求日益迫切. 芯片设计公司作为科技产业链中的关键一环,不仅要在 ...
- mac brew install Error: No available formula with the name “*“的解决办法
背景 在mac上使用brew安装软件发生错误 解决办法 执行以下命令即可 rm -rf /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core ...
- CLR via C# 笔记 -- 计算限制的异步操作(27)
1. 线程池基础. 创建和销毁线程是一个昂贵的操作,要耗费大量时间.太多的线程会浪费内存资源.由于操作系统必须调度可运行的线程并执行上下文切换,所以大多的线程还对性能不利.为了改善这个情况,CLR包含 ...
- 【译】Visual Studio 2022 - 17.10 性能增强
我们很高兴地宣布 Visual Studio 2022 的最新更新,它为您带来了 IDE 各个领域的一系列性能增强.在这篇博客中,我们将重点介绍17.10版本中一些最显著的改进,比如更快的 Windo ...