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 ;
}

最新文章

  1. 【原】iOS学习之NSDate在项目中的一些类目扩展
  2. .net 导出Excel功能
  3. Java NIO 基础
  4. MVVMlight框架应用:Data Binding、Command
  5. 算法教程(2)zz
  6. 浏览器不支持HTML5
  7. php入门实现留言板
  8. PL/SQL Developer不安装客户端连接远程oracle数据库(转)
  9. oracle存储过程 --1
  10. bzoj 1197
  11. hdu1115(重力算法的多边形中心)
  12. 从canvas理解面向对象
  13. 洛谷 P3377 【模板】左偏树(可并堆)
  14. C#设计模式之二十职责链模式(Chain of Responsibility Pattern)【行为型】
  15. 关于java和c语言中,变量重名问题
  16. MySQL之高可用MHA部署
  17. Linux Shell的 &amp; 、&amp;&amp; 、 ||
  18. LLVM/Clang编译相关研究
  19. 实现后门程序以及相应的rootkits,实现对后门程序的隐藏
  20. 绘制bitmap 全屏 安卓获取 屏幕大小

热门文章

  1. 1087 有多少不同的值 (20 分)C语言
  2. Python 任务自动化工具 tox 教程
  3. 聊聊密码学中的DES算法
  4. Quartz.NET总结(八)如何根据自己需要配置Topshelf 服务
  5. JavaScript中函数式编程中文翻译
  6. Eclipse直接运行算法第4版例子(重定向和读取指定路径文件)
  7. 重拾c++第三天(5):循环和关系表达式
  8. cogs 3. 服务点设置 dijkstra
  9. 第二篇:python中的字符串资源详述
  10. 【UEFI】---BIOS中对Guid的使用以及Lib函数的使用总结