CF#345 div2 A\B\C题
A题:
贪心水题,注意1,1这组数据,坑了不少人
#include <iostream>
#include <cstring>
using namespace std; int main()
{
int a1,a2;
while(cin>>a1>>a2)
{
int i=0;
int b = max(a1,a2);
int s = min(a1,a2);
if(b==1 && s==1) {
cout<<0<<endl;
continue;
}
for(i = 1;i <= 10000;i++)
{
b -= 2;
s += 1;
if(!b || !s) break;
if(s > b) {
int tmp = b;
b = s;
s = tmp;
}
}
cout<<i<<endl;
}
return 0;
}
B题:
首先给数组排序,然后问题就可以抽象成找到一个有序数组的上升子序列的最大个数,实现方法有点笨拙(我宁愿称之为巧妙:))
#include <iostream>
#include <cstring>
#include <algorithm>
#define INF 99999
using namespace std; int num[1007][1007]; int main(){
int n;
int a[1007];
while(cin>>n)
{
int ans = 0;
memset(num,0,sizeof(num));
for(int i = 1;i <= n;i++)
cin>>a[i];
sort(a+1,a+1+n);
//初始化第一个
int cnt = 0;
int Min = INF;
num[1][++cnt]++;
int tmp = a[1];
for(int i = 2;i <= n;i++)
{
if(a[i] == tmp) num[1][cnt]++;
else {
tmp = a[i];
num[1][++cnt]++;
}
}
for(int i = 1;i <= cnt;i++)
Min = min(Min,num[1][i]);
int y = 1;
while(cnt) {
ans += (cnt-1)*Min;
int tcount = 0;
for(int i = 1;i <= cnt;i++)
{
num[y][i] -= Min;
if(num[y][i])
num[y+1][++tcount] = num[y][i];
}
cnt = tcount;
y++;
Min = INF;
for(int i = 1;i <= cnt;i++)
Min = min(Min,num[y][i]);
}
cout<<ans<<endl;
}
return 0;
}
C题:
将二者的计算公式稍作推导就可以发现任意两点要符合要求,只要xy两个坐标只要满足(x||y)的复合命题为真即可。然后至于数组的大小,这里引用了特殊的数据结构来存储大量的数据,然后注意x或y坐标相同有n个点,而ans是要加或减n*(n-1)/2的
#include <iostream>
#include <map>
#include <cstdio>
#define ll long long
using namespace std; map<ll,ll> num_x;
map<ll,ll> num_y;
map<pair<ll,ll>,ll> num_s;
ll tx,ty; int main()
{
int n;
while(cin>>n)
{
ll ans = 0;
num_x.clear();
num_y.clear();
num_s.clear();
for(int i = 1;i <= n;i++)
{
scanf("%I64d%I64d",&tx,&ty);
num_x[tx]++;
num_y[ty]++;
num_s[make_pair(tx,ty)]++;
}
map<ll,ll>::iterator it1;
map<pair<ll,ll>,ll>::iterator it2;
for(it1 = num_x.begin();it1 != num_x.end();it1++)
ans += it1->second*(it1->second-1)/2;
for(it1 = num_y.begin();it1 != num_y.end();it1++)
ans += it1->second*(it1->second-1)/2;
for(it2 = num_s.begin();it2 != num_s.end();it2++)
ans -= it2->second*(it2->second-1)/2;
printf("%I64d\n",ans);
}
return 0;
}
CF#345 div2 A\B\C题的更多相关文章
- cf 442 div2 F. Ann and Books(莫队算法)
cf 442 div2 F. Ann and Books(莫队算法) 题意: \(给出n和k,和a_i,sum_i表示前i个数的和,有q个查询[l,r]\) 每次查询区间\([l,r]内有多少对(i, ...
- CF上的3道小题(2)
CF上的3道小题(2) T1:CF630K Indivisibility 题意:给出一个数n,求1到n的数中不能被2到9中任意一个数整除的数. 分析:容斥一下,没了. 代码: #include < ...
- CF上的3道小题(1)
CF上的3道小题 终于调完了啊.... T1:CF702E Analysis of Pathes in Functional Graph 题意:你获得了一个n个点有向图,每个点只有一条出边.第i个点的 ...
- 清橙A1206.小Z的袜子 && CF 86D(莫队两题)
清橙A1206.小Z的袜子 && CF 86D(莫队两题) 在网上看了一些别人写的关于莫队算法的介绍,我认为,莫队与其说是一种算法,不如说是一种思想,他通过先分块再排序来优化离线查询问 ...
- CF #324 DIV2 E题
这题很简单,把目标位置排序,把目标位置在当前位置前面的往前交换,每次都是贪心选择第一个满足这样要求的数字. #include <iostream> #include <cstdio& ...
- CF #324 DIV2 C题
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> ...
- CF #323 DIV2 D题
可以知道,当T较大时,对于LIS,肯定会有很长的一部分是重复的,而这重复的部分,只能是一个block中出现次数最多的数字组成一序列.所以,对于T>1000时,可以直接求出LIS,剩下T-=100 ...
- CF #316 DIV2 D题
D. Tree Requests time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
- CF#345 (Div1)
论蒟蒻如何被cf虐 以下是身败名裂后的题解菌=========== Div1 A.Watchmen 有n个点,每个点有一个坐标.求曼哈顿距离=欧几里得距离的点对数量. 只需要统计x或y一样的点对数量. ...
随机推荐
- Cobar是提供关系型数据库(MySQL)分布式服务的中间件
简介 Cobar是提供关系型数据库(MySQL)分布式服务的中间件,它可以让传统的数据库得到良好的线性扩展,并看上去还是一个数据库,对应用保持透明. 产品在阿里巴巴稳定运行3年以上. 接管了3000+ ...
- [Javascript] Advanced Function Scope
Something like 'for' or 'while', 'if', they don't create a new scope: ,,]; ; i < ary.length; i++) ...
- [转] DAG算法在hadoop中的应用
http://jiezhu2007.iteye.com/blog/2041422 大学里面数据结构里面有专门的一章图论,可惜当年没有认真学习,现在不得不再次捡 起来.真是少壮不努力,老大徒伤悲呀!什么 ...
- 使用nice命令调整进程优先级
Adjusting Process Priority with nice When Linux processes are started, they are started with a spe ...
- nginx 站点80跳443配置
server { listen 80; server_name www.furhacker.cn; location /{# return 301; rewrite ^(.*)$ https://$h ...
- ASP.NET-FineUI开发实践-9(三)
1. TextChanged事件前台触发回发后台,接上文,先给TextBox1加上事件,看看是怎么生成出来的, 注意AutoPostBack="true",找源代码,f4多出了个 ...
- jquery插件--多行文本缩略
1.webkit内核多行缩略样式 text-overflow:ellipsis; display:-webkit-box; -webkit-line-clamp:3; -webkit-box-orie ...
- elasticsearch中的概念简述
Near Realtime(NRT) Elasticsearch接近实时.从为一个文档建立索引到可被搜索,正常情况下有1秒延迟. Cluster 一个集群有一个唯一的名字,默认是"elast ...
- GridView、Repeater获取当前行号
GridView: <%# Container.DataItemIndex+1 %> Repeater:<%# Container.ItemIndex+1%>
- Maven 打包可运行 jar
为配合自动化部署hudson,最近研究了如何将eclipse maven工程打包成可运行的jar函数及对应的资源文件. 由于我们工程中包含了多个可运行的任务,在打包成jar时需要分别导出,p ...