cf112ABCE

54 篇文章 0 订阅

A. Supercentral Point
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points(x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):

  • point (x', y') is (x, y)'s right neighbor, if x' > x and y' = y
  • point (x', y') is (x, y)'s left neighbor, if x' < x and y' = y
  • point (x', y') is (x, y)'s lower neighbor, if x' = x and y' < y
  • point (x', y') is (x, y)'s upper neighbor, if x' = x and y' > y

We'll consider point (x, y) from the given set supercentral, if it has at least one upper, at least one lower, at least one left and at least one right neighbor among this set's points.

Vasya marked quite many points on the paper. Analyzing the picture manually is rather a challenge, so Vasya asked you to help him. Your task is to find the number of supercentral points in the given set.

Input

The first input line contains the only integer n (1 ≤ n ≤ 200) — the number of points in the given set. Next n lines contain the coordinates of the points written as "x y" (without the quotes) (|x|, |y| ≤ 1000), all coordinates are integers. The numbers in the line are separated by exactly one space. It is guaranteed that all points are different.

Output

Print the only number — the number of supercentral points of the given set.

Examples
input
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
output
2
input
5
0 0
0 1
1 0
0 -1
-1 0
output
1
Note

In the first sample the supercentral points are only points (1, 1) and (1, 2).

In the second sample there is one supercental point — point (0, 0).

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
int visx[1010];
int visxf[1010];
int visy[1010];
int visyf[1010];
struct Node{
	int x,y;
}A[210];
int main()
{
	int i,j,k,n;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d%d",&A[i].x,&A[i].y);
	}int ans=0;
	for(i=0;i<n;++i){
		bool sign1=false,sign2=false,sign3=false,sign4=false;
		for(j=0;j<n;++j){
			if(j==i)continue;
			if(A[j].y==A[i].y&&A[j].x>A[i].x)sign1=true;
			if(A[j].y==A[i].y&&A[j].x<A[i].x)sign2=true;
			if(A[j].x==A[i].x&&A[j].y>A[i].y)sign3=true;
			if(A[j].x==A[i].x&&A[j].y<A[i].y)sign4=true;
		}
		if(sign1&&sign2&&sign3&&sign4)ans++;
	}
	printf("%d\n",ans);
	return 0;
}

B. Burning Midnight Oil
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

One day a highly important task was commissioned to Vasya — writing a program in a night. The program consists of n lines of code. Vasya is already exhausted, so he works like that: first he writes v lines of code, drinks a cup of tea, then he writes as much as  lines, drinks another cup of tea, then he writes  lines and so on: , ...

The expression  is regarded as the integral part from dividing number a by number b.

The moment the current value  equals 0, Vasya immediately falls asleep and he wakes up only in the morning, when the program should already be finished.

Vasya is wondering, what minimum allowable value v can take to let him write not less than n lines of code before he falls asleep.

Input

The input consists of two integers n and k, separated by spaces — the size of the program in lines and the productivity reduction coefficient, 1 ≤ n ≤ 1092 ≤ k ≤ 10.

Output

Print the only integer — the minimum value of v that lets Vasya write the program in one night.

Examples
input
7 2
output
4
input
59 9
output
54
Note

In the first sample the answer is v = 4. Vasya writes the code in the following portions: first 4 lines, then 2, then 1, and then Vasya falls asleep. Thus, he manages to write 4 + 2 + 1 = 7 lines in a night and complete the task.

In the second sample the answer is v = 54. Vasya writes the code in the following portions: 546. The total sum is 54 + 6 = 60, that's even more than n = 59.

二分

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=10010;
long long n,k;
bool judge(long long mid){
	long long ans=mid,kk=k;
	while(mid/kk){
		ans+=mid/kk;
		kk*=k;
	}
	return ans>=n;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	long long l=1,r=n*k+1,ans;
	while(l<=r){
		long long mid=(l+r)>>1;
		if(judge(mid)){
			ans=mid;
			r=mid-1;
		}else {
			l=mid+1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

C. Another Problem on Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A string is binary, if it consists only of characters "0" and "1".

String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their positions of occurrence are different. So, if some string occurs multiple times, we should consider it the number of times it occurs.

You are given a binary string s. Your task is to find the number of its substrings, containing exactly k characters "1".

Input

The first line contains the single integer k (0 ≤ k ≤ 106). The second line contains a non-empty binary string s. The length of s does not exceed 106 characters.

Output

Print the single number — the number of substrings of the given string, containing exactly k characters "1".

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cincout streams or the %I64dspecifier.

Examples
input
1
1010
output
6
input
2
01010
output
4
input
100
01010
output
0
Note

In the first sample the sought substrings are: "1", "1", "10", "01", "10", "010".

In the second sample the sought substrings are: "101", "0101", "1010", "01010".

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1000010;
char str[maxn];
long long num[maxn];
int main()
{
	long long ans=0,k,cnt=1;
	scanf("%lld%s",&k,str);
	long long l=1,r,len=strlen(str),temp=0;num[0]=-1;
	if(k==0){
		l=0;
		for(long long i=0;i<len;++i){
			if(str[i]=='1'){
				r=i-l;l=i+1;
				ans=ans+r*(r+1)/2;
				//cout<<ans<<endl;
			}
		}
		r=(len-l);
		ans=ans+r*(r+1)/2;
		cout<<ans<<endl;
		return 0;
	}
	for(long long i=0;i<len;++i){
		if(str[i]=='1'){
			temp++;num[cnt++]=i;
		}
		if(temp==k+1){
			ans=ans+(num[l]-num[l-1])*(num[cnt-1]-num[cnt-2]);l++;temp--;
			//cout<<num[l]-num[l-1]<<endl;
		}
	}
	if(temp==k){
		ans=ans+(num[l]-num[l-1])*(len-num[cnt-1]);
	}
	cout<<ans<<endl;
	return 0;
}

E. Compatible Numbers
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Two integers x and y are compatible, if the result of their bitwise "AND" equals zero, that is, a & b = 0. For example, numbers 90(10110102) and 36 (1001002) are compatible, as 10110102 & 1001002 = 02, and numbers 3 (112) and 6 (1102) are not compatible, as 112 & 1102 = 102.

You are given an array of integers a1, a2, ..., an. Your task is to find the following for each array element: is this element compatible with some other element from the given array? If the answer to this question is positive, then you also should find any suitable element.

Input

The first line contains an integer n (1 ≤ n ≤ 106) — the number of elements in the given array. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 4·106) — the elements of the given array. The numbers in the array can coincide.

Output

Print n integers ansi. If ai isn't compatible with any other element of the given array a1, a2, ..., an, then ansi should be equal to -1. Otherwise ansi is any such number, that ai & ansi = 0, and also ansi occurs in the array a1, a2, ..., an.

Examples
input
2
90 36
output
36 90
input
4
3 6 3 6
output
-1 -1 -1 -1
input
5
10 6 9 8 2
output
-1 8 2 2 8

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<list>
#include<cmath>
#include<vector>
using namespace std;
const int maxn=1000010;
int num[maxn];
int dp[(1<<23)+1];
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	memset(dp,-1,sizeof(dp));
	for(i=1;i<=n;++i){
		scanf("%d",&num[i]);
		dp[num[i]^((1<<22)-1)]=num[i];//把num[i]的二进制中为1的数变为0 
	}
	for(i=(1<<22)-1;i>=0;--i){
		if(dp[i]==-1){
			for(j=0;j<=22;++j){
				if(dp[i|(1<<j)]!=-1){
					dp[i]=dp[i|(1<<j)];//如果i中的某个二进制中的0换成1有对应则0也可以对应此数 
					break;
				}
			}
		}
	}
	for(i=1;i<=n;++i){
		if(i==n)
			printf("%d\n",dp[num[i]]);
		else 
			printf("%d ",dp[num[i]]);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值