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一样的点对数量. ...
随机推荐
- 实用bootstrap 表格控件
http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html
- Lucene自定义扩展QueryParser
Lucene版本:4.10.2 在使用lucene的时候,不可避免的需要扩展lucene的相关功能来实现业务的需要,比如搜索时,需要在满足一个特定范围内的document进行搜索,如年龄在20和30岁 ...
- WCF的回调使用实例代码说明
很多时候我们会遇到,信息及时推送通知的情况,例如:监控设备时及时推送状态.报警信息等,我们就可以用WCF的回调机制来实现,下面以一个监控设备名字为例,如果设备名字发生改变,服务器就马上推送消息给客户端 ...
- intellij安装Scala及Python插件
1.下载intellij及Scala和Python插件 intellij的下载地址:https://www.jetbrains.com/idea/download/#section=windows S ...
- Java基础知识强化71:正则表达式之基本规则 和 常用正则表达式
1. 基本规则: A:字符 x 字符 x.举例:'a'表示字符a \\ 反斜线字符. \n 新行(换行)符 ('\u000A') \r 回车符 ('\u000D') B:字符类 [abc] a.b 或 ...
- 怎么在Linux上下载并安装ESET NOD32 Antivirus 4桌面版
转自:怎么在Linux上下载并安装ESET NOD32 Antivirus 4桌面版 下载并安装ESET NOD32 Antivirus 4的Linux桌面版,根据下面的步骤一步一步的来: I. 下 ...
- nyoj 2
#include <iostream> #include <stack> #include <string.h> #include <stdio.h> ...
- hdu 2190
//hdu2190 水题 题意是给一个n*3的教室,用1*1,2*2的砖去铺满,有多少种铺法,一开始没发现这个规律,想了一下,应该是递归. #include <iostream> usi ...
- css布局之负margin妙用及其他实现
相信大家在项目的开发中都遇到过这样的需求,一行放X(X>1)个块且相邻块之间的间距相同. 大概就是上面这个样子,下面介绍几种实现的方式. 1.负margin大法 设置好元素的宽度和留白占满父级的 ...
- Arcgis server - ' packaging failed '
我在使用ARCCatalog发布地图服务时,报这个错:packaging failed 然后我从头试,发现它提示说我的目录'C:\Users\Administrator\AppData\Local\E ...