Codeforces_845
A.排序,比较中间两个大小。
#include<bits/stdc++.h>
using namespace std; int n,a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= *n;i++) cin >> a[i];
sort(a+,a++n*);
reverse(a+,a++n*);
if(a[n] > a[n+]) cout << "YES" << endl;
else cout << "NO" << endl;
return ;
}
B.优先改变价值大的位置。
#include<bits/stdc++.h>
using namespace std; int n,sub[],add[];
string s; int main()
{
ios::sync_with_stdio();
cin >> s;
int sum1 = ,sum2 = ;
for(int i = ;i < ;i++)
{
sum1 += s[i]-'';
sub[i] = s[i]-'';
add[i] = ''-s[i];
}
for(int i = ;i < ;i++)
{
sum2 += s[i]-'';
sub[i] = s[i]-'';
add[i] = ''-s[i];
}
if(sum1 > sum2)
{
int t = sum1-sum2;
int a[];
for(int i = ;i < ;i++) a[i] = sub[i];
for(int i = ;i < ;i++) a[i] = add[i];
sort(a,a+);
reverse(a,a+);
for(int i = ;i < ;i++)
{
t -= a[i];
if(t <= )
{
cout << i+ << endl;
return ;
}
}
}
else if(sum2 > sum1)
{
int t = sum2-sum1;
int a[];
for(int i = ;i < ;i++) a[i] = add[i];
for(int i = ;i < ;i++) a[i] = sub[i];
sort(a,a+);
reverse(a,a+);
for(int i = ;i < ;i++)
{
t -= a[i];
if(t <= )
{
cout << i+ << endl;
return ;
}
}
}
else cout << << endl;
return ;
}
C.按l排序,优先队列模拟,处理出最小需要的TV数量。
#include<bits/stdc++.h>
using namespace std; int n;
struct xx
{
int l,r;
friend bool operator<(xx a,xx b)
{
return a.l < b.l;
}
}a[]; int main()
{
ios::sync_with_stdio();
cin >> n;
for(int i = ;i <= n;i++) cin >> a[i].l >> a[i].r;
sort(a+,a++n);
int ans = ;
priority_queue< int,vector<int>,greater<int> > q;
for(int i = ;i <= n;i++)
{
if(q.empty() || a[i].l <= q.top())
{
ans++;
q.push(a[i].r);
}
else
{
q.pop();
q.push(a[i].r);
}
}
if(ans > ) cout << "NO" << endl;
else cout << "YES" << endl;
return ;
}
D.栈模拟。
#include<bits/stdc++.h>
using namespace std; int n; int main()
{
ios::sync_with_stdio();
cin >> n;
stack<int> s;
int ans = ,now,cntover = ;
while(n--)
{
int x,y;
cin >> x;
if(x == ) cin >> now;
else if(x == )
{
ans += cntover;
cntover = ;
}
else if(x == )
{
cin >> y;
s.push(y);
}
else if(x == ) cntover = ;
else if(x == )
{
while(!s.empty()) s.pop();
}
else cntover++;
while(!s.empty() && now > s.top())
{
ans++;
s.pop();
}
}
cout << ans << endl;
return ;
}
G.dfs,每遇到环可以存起来,最后更新答案。
#include<bits/stdc++.h>
using namespace std; int n,m,a[],vis[] = {};
struct xx
{
int to,w;
xx(int a,int b):to(a),w(b){};
};
vector<xx> v[];
vector<int> vv; void add(int x)
{
for(int i = ;i < vv.size();i++) x = min(x,x^vv[i]);
if(x) vv.push_back(x);
} void dfs(int now,int val)
{
vis[now] = ;
a[now] = val;
for(int i = ;i < v[now].size();i++)
{
int t = v[now][i].to,w = v[now][i].w;
if(vis[t]) add(val^w^a[t]);
else dfs(t,w^val);
}
}
int main()
{
ios::sync_with_stdio();
cin >> n >> m;
while(m--)
{
int x,y,z;
cin >> x >> y >> z;
v[x].push_back(xx(y,z));
v[y].push_back(xx(x,z));
}
dfs(,);
for(int i = ;i < vv.size();i++) a[n] = min(a[n],a[n]^vv[i]);
cout << a[n] << endl;
return ;
}
Codeforces_845的更多相关文章
随机推荐
- 聊聊密码学中的DES算法
用心分享,共同成长 没有什么比你每天进步一点点更实在了 本文已经收录至我的github,欢迎大家踊跃star 和 issues. https://github.com/midou-tech/artic ...
- C++中重载、重写(覆盖)和隐藏的区别
转载自:https://blog.csdn.net/zx3517288/article/details/48976097 基本概念: 重载:是指同一可访问区内被声明的几个具有不同参数列(参数的类型,个 ...
- NetCore 启动地址配置详解
背景 程序在发布部署时候,设置环境ASPNETCORE_URLS不生效,也没在代码里使用UseUrls("xxxx"),启动一直是http://localhost:5000.最后测 ...
- 开箱即用!使用Rancher 2.3 启用Istio初体验
本文来自Rancher Labs Rancher的理念是Run Kubernetes Everywhere,Rancher 2.3中许多重大更新,让这一理念的实现又向前一步. 其中,最重要的两个特性是 ...
- 使用JavaMail发送邮件(含文本/附件/图片)的工具类
记录利用公司内搭建的smtp邮件服务器,使用javax mail发送邮件的程序 package com.test.mailTest; import java.util.Date; import jav ...
- 【原创】快速失败机制&失败安全机制
这是why技术的第29篇原创文章 之前在写<这道Java基础题真的有坑!我求求你,认真思考后再回答.>这篇文章时,我在8.1小节提到了快速失败和失败安全机制. 但是我发现当我搜索" ...
- Java 中的foreach(增强for循环)
foreach概述 增强for循环:底层使用的是送代器,使用for循环的格式,简化了送代器的书写,foreach是JDK1.5之后出现的新特性 使用增强for循环 遍历集合 /** * 遍历集合 * ...
- wannafly camp day4
2088: 电音之王 描述 题目描述: 终于活成了自己讨厌的样子. 听说多听电音能加快程序运行的速度. 定义一个数列,告诉你a0,a1,m0,m1,ca\_0,a\_1,m\_0,m\_1,ca0, ...
- git 工作实用创建删除分支
一.创建分支 .创建本地分支并切换 git checkout -b dev_wt2 .创建切换并关联远程分支 git checkout -b dev_wt3 orgin/dev_wt3 .创建远程分支 ...
- url的分发
一.分发 补充:通过查看源码:可以通过二级路由include进行二次分发 位置:urls.py urlpatterns = [ path('admin/', admin.site.urls), pat ...