Educational Codeforces Round 15
昨天做cf的时候自己跟自己抢了一晚上的网。。。。。大半的时间都花在验证网络账号。就因为手机和pc端不能同时连。。
好了,进入正题
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
using namespace std;
const int N=110000;
int f[N];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&f[i]);
int ans=1;
int cnt=1;
for(int i=1;i<n;i++)
{
if(f[i]>f[i-1]){
cnt++;
ans=max(ans,cnt);
}
else
cnt=1;
}
printf("%d\n",ans);
return 0;
}
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 xexists 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.
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<stdlib.h>
using namespace std;
const int N=110000;
long long f[35];
map<long long,int>mp;
long long a[N];
int main()
{
int n;
int cnt=1;
f[0]=1;
for(int i=1;f[i]<=2*1e9+10;i++)
{
f[i]=f[i-1]*2;
if(f[i]>2*1e9+10)
break;
}
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%I64d",&a[i]);
mp[a[i]]++;
}
long long ans=0;
for(int i=0;i<=34;i++)
{
for(int j=0;j<n;j++)
{
long long tmp=f[i]-a[j];
if(a[j]==tmp)
{
ans+=mp[tmp]-1;
}
else
ans+=mp[tmp];
}
}
printf("%I64d\n",ans/2);
return 0;
}
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
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<stdlib.h>
using namespace std;
const int N=110000;
long long f[35];
map<int,int>mp;
int c[2*N];
int d[N];
int main()
{
int n,m;
scanf("%d %d",&n,&m);
for(int i=0;i<n;i++)
scanf("%d",&c[i]);
for(int i=n;i<n+m;i++)
{
scanf("%d",&c[i]);
mp[c[i]]++;
}
sort(c,c+n+m);
int k=0;
for(int i=0;i<n+m;i++)
{
if(mp[c[i]])
d[k++]=i;
}
int ans=0;
int t=0;
int cnt;
for(int i=0;i<n+m;i++)
{
if(mp[c[i]])
{
t++;
}
else
{
if(t==0)
{
cnt=c[d[t]]-c[i];
}
else if(t==k){
cnt=c[i]-c[d[t-1]];
}
else
{
cnt=min(c[i]-c[d[t-1]],c[d[t]]-c[i]);
}
//cout<<c[i]<<" "<<c[d[t-1]]<<" "<<c[d[t]]<<endl;
ans=max(ans,cnt);
}
}
printf("%d\n",ans);
return 0;
}