Educational Codeforces Round 15 A, B , C 暴力 , map , 二分
1 second
256 megabytes
standard input
standard output
You are given array consisting of n integers. Your task is to find the maximum length of an increasing subarray of the given array.
A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous.
The first line contains single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print the maximum length of an increasing subarray of the given array.
5
1 7 2 11 15
3
6
100 100 100 100 100 100
1
3
1 2 3
3
题意:找到连续的上升子序列;
思路:暴力就行;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int a[M];
int main()
{
int x,y,z,i,t;
scanf("%d",&x);
int ans=,sum=,pre=;
for(i=;i<=x;i++)
{
scanf("%d",&y);
if(y>pre)
sum++;
else
sum=;
pre=y;
ans=max(ans,sum);
}
printf("%d\n",ans);
return ;
}
3 seconds
256 megabytes
standard input
standard output
You are given n integers a1, a2, ..., an. Find the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2 (i. e. some integer x exists so that ai + aj = 2x).
The first line contains the single positive integer n (1 ≤ n ≤ 105) — the number of integers.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
4
7 3 2 1
2
3
1 1 1
3
In the first example the following pairs of indexes include in answer: (1, 4) and (2, 4).
In the second example all pairs of indexes (i, j) (where i < j) include in answer.
题意:n个数,选两个相加求为2的阶乘的个数;
思路:两个数相加最大为2e9,一共30个数;枚举二的阶乘;
复杂度N*30;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
int er[];
int a[M];
map<int,int>m;
int main()
{
int x,y,z,i,t;
for(i=;i<=;i++)
er[i]=(<<i);
scanf("%d",&x);
for(i=;i<=x;i++)
scanf("%d",&a[i]),m[a[i]]++;
ll ans=;
for(i=;i<=x;i++)
{
for(t=;t<=;t++)
{
int v=er[t]-a[i];
if(v==a[i])
ans+=m[v]-;
else
ans+=m[v];
}
}
printf("%I64d\n",ans/);
return ;
}
3 seconds
256 megabytes
standard input
standard output
You are given n points on the straight line — the positions (x-coordinates) of the cities and m points on the same line — the positions (x-coordinates) of the cellular towers. All towers work in the same way — they provide cellular network for all cities, which are located at the distance which is no more than r from this tower.
Your task is to find minimal r that each city has been provided by cellular network, i.e. for each city there is at least one cellular tower at the distance which is no more than r.
If r = 0 then a tower provides cellular network only for the point where it is located. One tower can provide cellular network for any number of cities, but all these cities must be at the distance which is no more than r from this tower.
The first line contains two positive integers n and m (1 ≤ n, m ≤ 105) — the number of cities and the number of cellular towers.
The second line contains a sequence of n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the coordinates of cities. It is allowed that there are any number of cities in the same point. All coordinates ai are given in non-decreasing order.
The third line contains a sequence of m integers b1, b2, ..., bm ( - 109 ≤ bj ≤ 109) — the coordinates of cellular towers. It is allowed that there are any number of towers in the same point. All coordinates bj are given in non-decreasing order.
Print minimal r so that each city will be covered by cellular network.
3 2
-2 2 4
-3 0
4
5 3
1 5 10 14 17
4 11 15
3 题意:在一个数轴上,有n个城市,m个信号塔;给出城市和信号塔的位置,求最小的信号塔影响范围;
思路:二分答案,check一下就行了;注意爆int;
#include<bits/stdc++.h>
using namespace std;
#define ll __int64
#define esp 0.00000000001
const int N=3e3+,M=1e6+,inf=1e9+,mod=;
ll a[M];
ll b[M];
int check(ll hh,int x,int y)
{
int u=;
int v=;
while(u<=x)
{
if(v>y)
return ;
if(a[u]>=b[v]-hh&&b[v]+hh>=a[u])
u++;
else
v++;
}
return ;
}
int main()
{
int x,y,z,i,t;
scanf("%d%d",&x,&y);
for(i=;i<=x;i++)
scanf("%I64d",&a[i]);
for(i=;i<=y;i++)
scanf("%I64d",&b[i]);
sort(a+,a++x);
sort(b+,b++y);
ll st=;
ll en=2e9;
while(st<en)
{
ll mid=(st+en)>>;
if(check(mid,x,y))
en=mid;
else
st=mid+;
}
printf("%I64d\n",st);
return ;
}
Educational Codeforces Round 15 A, B , C 暴力 , map , 二分的更多相关文章
- Codeforces Educational Codeforces Round 15 A. Maximum Increase
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 8 A. Tennis Tournament 暴力
A. Tennis Tournament 题目连接: http://www.codeforces.com/contest/628/problem/A Description A tennis tour ...
- Codeforces Educational Codeforces Round 15 C. Cellular Network
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 (A - E)
比赛链接:http://codeforces.com/contest/702 A. Maximum Increase A题求连续最长上升自序列. [暴力题] for一遍,前后比较就行了. #inclu ...
- Educational Codeforces Round 15 C. Cellular Network(二分)
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 C 二分
C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- Educational Codeforces Round 15 A dp
A. Maximum Increase time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph
E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...
- Codeforces Educational Codeforces Round 15 D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
随机推荐
- POJ1751 Highways
题目链接 http://poj.org/problem?id=1751 题目大意:输入n:然后给你n个点的坐标(任意两点之间皆可达):输入m:接下来m行每行输入两个整数x,y表示 点x与点y 已 ...
- c++获取读写文本权限
#include<cstdio> #include<iostream> #include<fstream> using namespace std; int tot ...
- DataTable数据导出到Excel,并发送到客户端进行下载
本代码实现思路是:页面显示和导出分开,导出的数据和用于页面显示的是同一查询数据方式,所以也是同样的数据,只是在导出数据时从数据库重新捞了一次数据.此导出数据方式会先将数据保存到Excel中,然后将创建 ...
- 封装AJax实现JSON前台与后台交互
实践技术点:1.AJax自定义封装 2.后台序列化与反序列化JSON 3.客户端解析JSON字符串,处理DOM 实现代码如下: 1.JS脚本代码: 1 /*** NOTE:AJAX处理JS TIM ...
- Shiro 页面权限标签
http://www.cnblogs.com/jifeng/p/4500410.html 不整理了,直接看人家写好的
- [python数据结构] hashable, list, tuple, set, frozenset
学习 cs212 unit4 时遇到了 tuple, list, set 同时使用的问题,并且进行了拼接.合并操作.于是我就被弄混了.所以在这里进行一下总结. hashable and unhasha ...
- php扩展redis链接失败,返回false
刚开始接触redis,发现一直返回false,其实只要关闭防火墙就可以连接成功了. 关闭selinux操作 方法1:修改grub.conf将参数selinux=1修改为等于selinux=0,这个 ...
- Linux三剑客之老二-------sed命令详解
sed命令 文件 编辑 本文索引 [隐藏] sed的选项.命令.替换标记 选项 参数 sed命令 sed替换标记 sed元字符集 sed用法实例 替换操作:s命令 全面替换标记g 定界符 删除操作:d ...
- iOS 载入图片选择imageNamed 方法还是 imageWithContentsOfFile?
Apple官方的文档为生成一个UIImage对象提供了两种方法: 1. imageNamed,其參数为图片的名字. 2. imageWithContentsOfFile,其參数也是图片文件的路径. 那 ...
- 方阵行列式并行化计算(OpenMP,MPI),并计算加速比
00][100].在创建方阵时,方阵的阶数N(N<100)由外部输入.然后用两层"for循环"来给方阵 p左上角 N×N个位置赋值.具体实现如下: /* * 定义矩阵阶数N ...