Educational Codeforces Round 15 A, B , C 暴力 , map , 二分
2016-08-07 15:21
495 查看
A. Maximum Increase
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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).
Output
Print the maximum length of an increasing subarray of the given array.
Examples
Input
Output
Input
Output
Input
Output
B. Powers of Two
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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).
Input
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).
Output
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
Examples
Input
Output
Input
Output
Note
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;
C. Cellular Network
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print minimal r so that each city will be covered by cellular network.
Examples
Input
Output
Input
Output
思路:二分答案,check一下就行了;注意爆int;
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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).
Output
Print the maximum length of an increasing subarray of the given array.
Examples
Input
5 1 7 2 11 15
Output
3
Input
6 100 100 100 100 100 100
Output
1
Input
3 1 2 3
Output
3 题意:找到连续的上升子序列; 思路:暴力就行;
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define esp 0.00000000001 const int N=3e3+10,M=1e6+10,inf=1e9+10,mod=1000000007; int a[M]; int main() { int x,y,z,i,t; scanf("%d",&x); int ans=0,sum=0,pre=0; for(i=1;i<=x;i++) { scanf("%d",&y); if(y>pre) sum++; else sum=1; pre=y; ans=max(ans,sum); } printf("%d\n",ans); return 0; }
B. Powers of Two
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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).
Input
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).
Output
Print the number of pairs of indexes i, j (i < j) that ai + aj is a power of 2.
Examples
Input
4 7 3 2 1
Output
2
Input
3 1 1 1
Output
3
Note
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+10,M=1e6+10,inf=1e9+10,mod=1000000007; int er[50]; int a[M]; map<int,int>m; int main() { int x,y,z,i,t; for(i=1;i<=30;i++) er[i]=(1<<i); scanf("%d",&x); for(i=1;i<=x;i++) scanf("%d",&a[i]),m[a[i]]++; ll ans=0; for(i=1;i<=x;i++) { for(t=1;t<=30;t++) { int v=er[t]-a[i]; if(v==a[i]) ans+=m[v]-1; else ans+=m[v]; } } printf("%I64d\n",ans/2); return 0; }
C. Cellular Network
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
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.
Input
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.
Output
Print minimal r so that each city will be covered by cellular network.
Examples
Input
3 2 -2 2 4 -3 0
Output
4
Input
5 3 1 5 10 14 17 4 11 15
Output
3 题意:在一个数轴上,有n个城市,m个信号塔;给出城市和信号塔的位置,求最小的信号塔影响范围;
思路:二分答案,check一下就行了;注意爆int;
#include<bits/stdc++.h> using namespace std; #define ll __int64 #define esp 0.00000000001 const int N=3e3+10,M=1e6+10,inf=1e9+10,mod=1000000007; ll a[M]; ll b[M]; int check(ll hh,int x,int y) { int u=1; int v=1; while(u<=x) { if(v>y) return 0; if(a[u]>=b[v]-hh&&b[v]+hh>=a[u]) u++; else v++; } return 1; } int main() { int x,y,z,i,t; scanf("%d%d",&x,&y); for(i=1;i<=x;i++) scanf("%I64d",&a[i]); for(i=1;i<=y;i++) scanf("%I64d",&b[i]); sort(a+1,a+1+x); sort(b+1,b+1+y); ll st=0; ll en=2e9; while(st<en) { ll mid=(st+en)>>1; if(check(mid,x,y)) en=mid; else st=mid+1; } printf("%I64d\n",st); return 0; }
相关文章推荐
- 【Educational Codeforces Round 6D】【暴力 SET二分】Professor GukiZ and Two Arrays
- Educational Codeforces Round 22-B. The Golden Age-暴力枚举+map
- Educational Codeforces Round 15 C. Cellular Network(二分)
- Educational Codeforces Round 15 C 二分+差分数组
- 【最长递增子序列+(不下降)二分栈】Educational Codeforces Round 15
- Educational Codeforces Round 15 C Cellular Network(二分)
- Educational Codeforces Round 15 C. Cellular Network (二分)
- Educational Codeforces Round 24 A 水 B stl C 暴力 D stl模拟 E 二分
- Educational Codeforces Round 15 C 二分
- Educational Codeforces Round 15 B. Powers of Two(暴力)
- Educational Codeforces Round 6 D. Professor GukiZ and Two Arrays(二分 | two pointers)
- Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds(二分 + 贪心)
- Codeforces Round #415 (Div. 2)A. Straight «A» (暴力)
- Educational Codeforces Round 15 D. Road to Post Office 数学
- Educational Codeforces Round 11 D. Number of Parallelograms 暴力
- Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
- Educational Codeforces Round 21 D ( 二分 )
- Educational Codeforces Round 21 D.Array Division(二分)
- Educational Codeforces Round 15 [111110]
- 【Educational Codeforces Round 2B】【map or 二分查找】Queries about less or equal elements b[]中的每个数比a[]中多少数大