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一样的点对数量. ...
随机推荐
- windows下Socket链接溢出
最近在windows下使用通过多线程使用jdbc操作数据库,在线程数设置为5,并且每个线程执行完成后Sleep(1000),在这种情况下,竟然还会报错: java.net.SocketExceptio ...
- Java基础知识强化31:String类之String的面试题
1.先看一个图: 2.String面试题: (1)题1: package cn.itcast_02; /* * 看程序写结果 */ public class StringDemo3 { public ...
- 【翻译】A (very) short introduction to R R的简短介绍
[前言] 本文翻译自Paul Torfs & Claudia Brauer的文章A (very) short introduction to R.其中比较简单的地方没有翻译,不好用中文描述的地 ...
- css中同时用头部引入和外部引入对同一个标签进行样式设置,哪一个优先级高。
这段是html中的代码 <!doctype html> <html lang="en"> <head> <meta charset=&qu ...
- Asp.Net Api2 过滤器的使用
1.注意: apiController控制器 对应的过滤器System.Web.Http.Filters.ActionFilterAttribute的过滤器 MVC的Controller控制器 对应的 ...
- 无法连接vCenter Server清单https://IP:10443
VMware vCenter Server服务器安装系统的时候使用一个IP,安装完VMware vCenter后来更换了另外一个IP,当使用vSphere Web Client登陆VMware vCe ...
- Hadoop参数优化
dfs.block.size 决定HDFS文件block数量的多少(文件个数),它会间接的影响Job Tracker的调度和内存的占用(更影响内存的使用), mapred.map.tasks.spec ...
- Sql server Compact 小型数据库损坏修复
之前碰到过小型数据库损坏打不开的问题,一直没有理会,今天生产上客户本地小库产生这样的问题,已经修复 SqlCeEngine engine = new SqlCeEngine(" ...
- rtmpdump代码分析 转
RTMPdump 源代码分析 1: main()函数 rtmpdump 是一个用来处理 RTMP 流媒体的工具包,支持 rtmp://, rtmpt://, rtmpe://, rtmpte://, ...
- view ondraw
窗口发生重绘时会被应用程序的窗口框架给调用 要使输出的东西始终能在窗口中看到 就可以使用该函数 窗口从到有的时候就会产生WM_PAINT消息,让窗口发生重绘 这是程序就会执行到ONDRAW函数处 所 ...