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一样的点对数量. ... 
随机推荐
- 初探swift语言的学习笔记四(类对象,函数)
			作者:fengsh998 原文地址:http://blog.csdn.net/fengsh998/article/details/29606137 转载请注明出处 假设认为文章对你有所帮助,请通过留言 ... 
- web页面缓存技术之Local Storage
			业务:检测页面文本框的值是否有改变,有的话存入缓存,并存储到数据库,这样用户异常操作后再用浏览器打开网页,就可避免重新填写数据 数据库表:Test,包含字段:PageName,PageValue BL ... 
- ERROR<53761> - Plugins - conn=-1 op=-1 msgId=-1 - Connection  Bind through PTA failed (91). Retrying...
			LDAP6.3在DSCC控制台启动实例完成,但是操作状态显示“意外错误”,查看日志如下: 04/May/2016:21:10:39 +0800] - Sun-Java(tm)-System-Direc ... 
- 使用多线程完成Socket
			public class Service { //服务器 public static void main(String[] args) { ServerSocket serverSocket=null ... 
- C# 面向对象  , 抽象基类
			抽象基类 关键字, abstract abstract class SSS { public void aaa() { } } 作为抽象基类, 只能在 继承关系 中 担任父类的角色,不能出现在其他地 ... 
- C# 面向对象  , 继承
			继承 class A { Console.WriteLine("hello world"); } class B:A { } 以上书写,表示B 是A 的子类, B 同时继承A 中 ... 
- 排序算法之快速排序 JAVA快速排序算法
			public static void quickSort(int[] arr, int low , int height){ int l=low, h = height; if(low < he ... 
- JS中window.showModalDialog()详解 HTML DOM open() 方法
			window.showModalDialog()方法用来创建一个显示HTML内容的模态对话框. window.showModelessDialog()方法用来创建一个显示HTML内容的非模态对话框. ... 
- QML之窗口(无边框、透明及拖拽)
			1.无边框 Qt Quick 2.0 中 QQuickView代替了1.0中的QDeclarativeView. 无边框窗口代码如下: QQuickView viwer; //QQuickView继承 ... 
- A Bug's Life(hdu1829种类并查集)
			题意:有一群虫子,现在给你一些关系,判断这些关心有没有错 思路:向量种类并查集,下面讲一下向量的种类并查集 本题的各个集合的关心有两种0同性,1异性,怎么判断有错, 1.先判断他们是否在一个集合,即父 ... 
