这次真的死脑筋了,明明可以特判却没有用,反而想着其他办法,出发点是好的,可惜想错了地方。。难受啊。
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.
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.
Print the only number — the number of supercentral points of the given set.
8 1 1 4 2 3 1 1 2 0 2 0 1 1 0 1 3
2
5 0 0 0 1 1 0 0 -1 -1 0
1
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;
}
}
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.
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 ≤ 109, 2 ≤ k ≤ 10.
Print the only integer — the minimum value of v that lets Vasya write the program in one night.
7 2
4
59 9
54题意:有n的作业量,现在一个人第1次完成v的作业量,第二次完成v / k的作业量,第三次完成v / (k*k)的作业量,直到作业量为0停止。满足 : 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;
}
公式是(暂无)
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".
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.
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 cin, cout streams or the %I64dspecifier.
1 1010
6
2 01010
4
100 01010
0
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);
}