[2018-5-11]BNUZ套题比赛div2

这次真的死脑筋了,明明可以特判却没有用,反而想着其他办法,出发点是好的,可惜想错了地方。。难受啊。
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
Copy
8
1 1
4 2
3 1
1 2
0 2
0 1
1 0
1 3
Output
Copy
2
Input
Copy
5
0 0
0 1
1 0
0 -1
-1 0
Output
Copy
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).

题意:这个题就是找点,要求一个点四周x,y轴十字方向都有点,然后计算有几个点就好了,直接暴力特判就好。
#include<bits/stdc++.h>
#define INF 2000
using namespace std;
struct a {
	int x,y;
} num[205];
int mark[2005][2005];
int main() {
	int n,xmax,xmin,ymax,ymin,count;
	while(~scanf("%d",&n)) {
		memset(mark,0,sizeof(mark));
		count = 0;
		for(int i = 0 ; i < n; i++) {
			scanf("%d %d",&num[i].x,&num[i].y);
		}
		int a,b,c,d;
		for(int i = 0; i < n; i++) {
			a = b= c = d = 0;
			for(int j = 0; j < n; j++) {
				if(num[i].x == num[j].x && num[i].y < num[j].y) {
					a = 1;
				}
				if(num[i].x == num[j].x && num[i].y > num[j].y) {
					b = 1;
				}
				if(num[i].x > num[j].x && num[i].y == num[j].y) {
					c = 1;
				}
				if(num[i].x < num[j].x && num[i].y == num[j].y) {
					d = 1;
				}
			}
			if(a && b && c && d) {
				count++;
			}
		}
		cout << count << endl;
	}
}

 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.

Sample test(s)
input
7 2
output
4
input
59 9
output
54
题意:有n的作业量,现在一个人第1次完成v的作业量,第二次完成v / k的作业量,第三次完成v / (k*k)的作业量,直到作业量为0停止。满足 : v + + + ... >=  n  这个式子,求v的最小值。
题解:有两种办法,一种是二分法,一种是推公式法;
二分法:
    #include <stdio.h>  
    #include <string.h>  
    int n, k;  
    int judge(int m) {  
        int sum = m;  
        while(m) {  
            sum += m/k;  
            m /= k;  
        }  
        if(sum >= n) return 1;  
        else return 0;  
    }  
    int main() {  
        while(~scanf("%d%d",&n,&k)) {  
            int ans;  
            int l = 1;  
            int r = n;  
            while(l <= r) {  
                int m = l+(r-l)/2;  
                if(judge(m)) {  
                    ans = m;  
                    r = m-1;  
                }  
                else l = m+1;  
            }  
            printf("%d\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.

Sample test(s)
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".

题意:给出一个二进制串,统计有多少中含有k个1的子串。
题解:听学长说,感觉也是公式,回来尝试后才明白,也算是公式题吧。
#include <bits/stdc++.h>
using namespace std;
long long num[1111111];
char str[1111111];

int main() {
	int k,cnt=0;
	long long ans=0;
	scanf("%d",&k);
	scanf("%s",str);
	num[0]=1;
	int len=strlen(str);
	for(int i=0; i<len; i++) {
		if(str[i]=='1') {//1的个数
			cnt++;
		}
		if(cnt>=k) {//截止到第i位,第 cnt-k 个1前面有几个0答案就有几种可能
			ans+=num[cnt-k];
		}
		num[cnt]++;//第cnt个1前面的0的个数(cnt从0开始)
	}
	printf("%lld\n",ans);
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值