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的更多相关文章
随机推荐
- Java工作流系统-父子流程的配置讲解
父子流程 关键字: 驰骋工作流程快速开发平台 工作流程管理系统 工作流引擎 asp.net工作流引擎 java工作流引擎. 开发者表单 拖拽式表单 工作流系统 适配数据库: oralce,mysql ...
- [开源] SEPP——研发协作一站式管理平台
演示地址 http://www.seqcer.com/ 仅对chrome浏览器做了完全适配,其他chromium核心浏览器或者firefox.safari也能使用,但是不推荐 仓库地址: 前端:htt ...
- ocx控件的坑
前言 这还是第一次写博客,以前太懒了,现在发现是很有必要记录下这些经验和问题的.最近项目中有个需求(报表单据需要客户签名,连接签字板,把签名单据同步到服务器上),需要和硬件交互,当时硬件商提供了ocx ...
- 在Winform界面中使用DevExpress的TreeList实现节点过滤查询的两种方式
在我较早的一篇随笔<在DevExpress程序中使用TeeList控件以及节点查询的处理>中,介绍了在树形列表TreeList控件上面,利用SearchControl实现节点的模糊查询过滤 ...
- 【转】python get-pip.py could not find a version that satisfies
转:https://blog.csdn.net/yanlisuo/article/details/81357305 转:https://blog.csdn.net/dyrlovewc/article/ ...
- HashMap 源码赏析 JDK8
一.简介 HashMap源码看过无数遍了,但是总是忘,好记性不如烂笔头. 本文HashMap源码基于JDK8. 文章将全面介绍HashMap的源码及HashMap存在的诸多问题. 开局一张图,先来看看 ...
- 探究公钥、私钥、对称加密、非对称加密、hash加密、数字签名、数字证书、CA认证、https它们究竟是什么,它们分别解决了通信过程的哪些问题。
一.准备 1. 角色:小白.美美.小黑. 2. 剧情:小白和美美在谈恋爱:小黑对美美求而不得.心生怨念,所以从中作梗. 3. 需求:小白要与美美需通过网络进行通信,联络感情,所以必须保证通信的安全性. ...
- python异常(理论知识)
异常 程序在运行过程当中,不可避免的会出现一些错误,比如: 使用了没有赋值过的变量 使用了不存在的索引 除0 ... 这些错误在程序中,我们称其为异常. 程序运行过程中,一旦出现异常将会导致程序立即终 ...
- js强制限制输入允许两位小数
<input type="text" value="@item.CostCash.Value.ToString("#0.00")" c ...
- 《C# 爬虫 破境之道》:第二境 爬虫应用 — 第一节:HTTP协议数据采集
首先欢迎您来到本书的第二境,本境,我们将全力打造一个实际生产环境可用的爬虫应用了.虽然只是刚开始,虽然路漫漫其修远,不过还是有点小鸡冻:P 本境打算针对几大派生类做进一步深耕,包括与应用的结合.对比它 ...