Codeforces Round #308 (Div. 2)
2015-06-19 16:19
232 查看
A. Vanya and Table
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya has a table consisting of 100 rows, each row contains 100 cells.
The rows are numbered by integers from 1 to 100 from
bottom to top, the columns are numbered from 1 to 100 from
left to right.
In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times).
After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.
Input
The first line contains integer n (1 ≤ n ≤ 100)
— the number of rectangles.
Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100),
where x1 and y1 are
the number of the column and row of the lower left cell and x2 and y2 are
the number of the column and row of the upper right cell of a rectangle.
Output
In a single line print the sum of all values in the cells of the table.
Sample test(s)
input
output
input
output
Note
Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will be equal to 18.
求一共几个数
B. Vanya and Books
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should
be assigned with a number from 1 to n.
Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input
The first line contains integer n (1 ≤ n ≤ 109)
— the number of books in the library.
Output
Print the number of digits needed to number all the books.
Sample test(s)
input
output
input
output
Note
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
求1-n的数一共有几位数字
C. Vanya and Scales
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams
where w is some integer not less than 2(exactly
one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can
be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and
some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
Input
The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109)
— the number defining the masses of the weights and the mass of the item.
Output
Print word 'YES' if the item can be weighted and 'NO' if it
cannot.
Sample test(s)
input
output
input
output
input
output
Note
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3,
and the second pan can have two weights of masses 9 and 1,
correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1,
and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
砝码是w的0到100次方,求能否称出重量m
dfs随便搞一搞
左面加,右面加,不加
D. Vanya and Triangles
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result
many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000)
— the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100)
— the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Sample test(s)
input
output
input
output
input
output
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
求n个点能构成多少个三角形。
先抛出重复点,然后枚举两个点,确定不在这条直线上的点的数目。在这条直线的点的数目可以通过,gcd找一下整点,再-100 - 100 找出是否这条线的点有没有点。。。
最后数/6
E. Vanya and Brackets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya is doing his maths homework. He has an expression of form
,
where x1, x2, ..., xn are
digits from 1 to 9, and sign
represents
either a plus '+' or the multiplication sign '*'. Vanya needs
to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
Input
The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is
odd), its odd positions only contain digits from 1 to 9,
and even positions only contain signs + and * .
The number of signs * doesn't exceed 15.
Output
In the first line print the maximum possible value of an expression.
Sample test(s)
input
output
input
output
input
output
Note
Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
我们要不要祭出python大法呢
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya has a table consisting of 100 rows, each row contains 100 cells.
The rows are numbered by integers from 1 to 100 from
bottom to top, the columns are numbered from 1 to 100 from
left to right.
In this table, Vanya chose n rectangles with sides that go along borders of squares (some rectangles probably occur multiple times).
After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result.
Input
The first line contains integer n (1 ≤ n ≤ 100)
— the number of rectangles.
Each of the following n lines contains four integers x1, y1, x2, y2 (1 ≤ x1 ≤ x2 ≤ 100, 1 ≤ y1 ≤ y2 ≤ 100),
where x1 and y1 are
the number of the column and row of the lower left cell and x2 and y2 are
the number of the column and row of the upper right cell of a rectangle.
Output
In a single line print the sum of all values in the cells of the table.
Sample test(s)
input
2 1 1 2 3 2 2 3 3
output
10
input
2 1 1 3 3 1 1 3 3
output
18
Note
Note to the first sample test:
Values of the table in the first three rows and columns will be as follows:
121
121
110So, the sum of values will be equal to 10.
Note to the second sample test:
Values of the table in the first three rows and columns will be as follows:
222
222
222
So, the sum of values will be equal to 18.
求一共几个数
#include <bits/stdc++.h> using namespace std; int n; int x1,yy1,x2,y2; int main() { cin>>n; int sum=0; while(n--) { cin>>x1>>yy1>>x2>>y2; sum+=(x2-x1+1)*(y2-yy1+1); } cout<<sum; return 0; }
B. Vanya and Books
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should
be assigned with a number from 1 to n.
Naturally, distinct books should be assigned distinct numbers.
Vanya wants to know how many digits he will have to write down as he labels the books.
Input
The first line contains integer n (1 ≤ n ≤ 109)
— the number of books in the library.
Output
Print the number of digits needed to number all the books.
Sample test(s)
input
13
output
17
input
4
output
4
Note
Note to the first test. The books get numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, which totals to 17 digits.
Note to the second sample. The books get numbers 1, 2, 3, 4, which totals to 4 digits.
求1-n的数一共有几位数字
#include <bits/stdc++.h> using namespace std; long long n; int main() { cin>>n; long long a=9,b=0; long long sum=0; int k=1; while(n>=a) { sum+=(a-b)*k; a*=10;a+=9; b*=10;b+=9; k++; } sum+=(n-b)*k; cout<<sum; return 0; }
C. Vanya and Scales
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w100 grams
where w is some integer not less than 2(exactly
one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can
be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and
some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
Input
The first line contains two integers w, m (2 ≤ w ≤ 109, 1 ≤ m ≤ 109)
— the number defining the masses of the weights and the mass of the item.
Output
Print word 'YES' if the item can be weighted and 'NO' if it
cannot.
Sample test(s)
input
3 7
output
YES
input
100 99
output
YES
input
100 50
output
NO
Note
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3,
and the second pan can have two weights of masses 9 and 1,
correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1,
and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
砝码是w的0到100次方,求能否称出重量m
dfs随便搞一搞
左面加,右面加,不加
#include <bits/stdc++.h> using namespace std; long long w,m; int flag; void dfs(long long b,long long c) { if(c==m) { flag=1; return ; } if(flag) return ; if(abs(b)<=m*w) { dfs(b*w,c+b); dfs(b*w,c-b); dfs(b*w,c); } return ; } int main() { flag=0; cin>>w>>m; if(w<=3) { cout<<"YES"<<endl; return 0; } dfs(1,0); if(flag) cout<<"YES"; else cout<<"NO"; return 0; }
D. Vanya and Triangles
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output
Vanya got bored and he painted n distinct points on the plane. After that he connected all the points pairwise and saw that as a result
many triangles were formed with vertices in the painted points. He asks you to count the number of the formed triangles with the non-zero area.
Input
The first line contains integer n (1 ≤ n ≤ 2000)
— the number of the points painted on the plane.
Next n lines contain two integers each xi, yi ( - 100 ≤ xi, yi ≤ 100)
— the coordinates of the i-th point. It is guaranteed that no two given points coincide.
Output
In the first line print an integer — the number of triangles with the non-zero area among the painted points.
Sample test(s)
input
40 01 12 02 2
output
3
input
30 01 12 0
output
1
input
11 1
output
0
Note
Note to the first sample test. There are 3 triangles formed: (0, 0) - (1, 1) - (2, 0); (0, 0) - (2, 2) - (2, 0); (1, 1) - (2, 2) - (2, 0).
Note to the second sample test. There is 1 triangle formed: (0, 0) - (1, 1) - (2, 0).
Note to the third sample test. A single point doesn't form a single triangle.
求n个点能构成多少个三角形。
先抛出重复点,然后枚举两个点,确定不在这条直线上的点的数目。在这条直线的点的数目可以通过,gcd找一下整点,再-100 - 100 找出是否这条线的点有没有点。。。
最后数/6
#include <bits/stdc++.h>
using namespace std;
#define Max 2333int x[2333];
int y[2333];
int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int mp[233][233]={};
int main()
{
int n;
cin>>n;
int aa,bb;
for(int i=1;i<=n;i++)
{
cin>>aa>>bb;
aa+=100;
bb+=100;
mp[aa][bb]=1;
}
int top=0;
for(int i=0;i<=200;i++)
{
for(int j=0;j<=200;j++)
{
if(mp[i][j])
{
x[++top]=i;
y[top]=j;
}
}
}
n=top;
long long sum=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(i!=j)
{
int u=-1;
int xa=x[i],ya=y[i];
int xb=x[j],yb=y[j];
int xx=xa-xb;
int yy=ya-yb;
int g;
if(xx==0||yy==0)
{
if(xx==0)
{
yy=1;
}
else xx=1;
}
else {g=gcd(xx,yy);
xx/=g;
yy/=g;}
int tx=xa;
int ty=ya;
while(tx<=200&&ty<=200&&tx>=0&&ty>=0)
{
tx+=xx;
ty+=yy;
if(!(tx<=200&&ty<=200&&tx>=0&&ty>=0)) break;
if(mp[tx][ty]) u++;
}
tx=xa;
ty=ya;
while(tx<=200&&ty<=200&&tx>=0&&ty>=0)
{
tx-=xx;
ty-=yy;
if(!(tx<=200&&ty<=200&&tx>=0&&ty>=0)) break;
if(mp[tx][ty]) u++;
}
sum+=(n-2-u);
}
}
}
cout<<sum/6;
return 0;
}
E. Vanya and Brackets
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Vanya is doing his maths homework. He has an expression of form
,
where x1, x2, ..., xn are
digits from 1 to 9, and sign
represents
either a plus '+' or the multiplication sign '*'. Vanya needs
to add one pair of brackets in this expression so that to maximize the value of the resulting expression.
Input
The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is
odd), its odd positions only contain digits from 1 to 9,
and even positions only contain signs + and * .
The number of signs * doesn't exceed 15.
Output
In the first line print the maximum possible value of an expression.
Sample test(s)
input
3+5*7+8*4
output
303
input
2+3*5
output
25
input
3*4*5
output
60
Note
Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.
Note to the second sample test. (2 + 3) * 5 = 25.
Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).
我们要不要祭出python大法呢
s = raw_input() ans = eval(s) l = len(s) a = [] for i in range (l): if (s[i] == '*'): a.append(i) for i in a: s1 = "(" + s[:i] + ")" + s[i:] ans = max(ans, eval(s1)) for j in a: if j > i: if s[j] == '*': s1 = s[:i+1] + "(" + s[i+1:j] + ")"+s[j:] ans = max(ans, eval(s1)) s1 = s[:i+1] + "(" + s[i + 1:] + ")" ans = max(ans, eval(s1)) print ans
相关文章推荐
- 医疗人群数据包
- GUI_Download的Codepage参数
- PHP正则把"2010-12-20"替换成"12/20/2010"
- uva 1151 - Buy or Build poj 2784 Buy or Build(最小生成树)
- 程序员的量化交易之路(36)--Lean之数据读取SubscriptionDataReader4
- 牛腩学习----Web编程安全问题
- python datetime对象转时间戳
- lftp命令使用
- python替换html实体的方法
- python 的对象序列化/反序列化
- python替换html实体的方法
- python 的对象序列化/反序列化
- sphinx数据文件简析-转
- sphinx配置文件中,关于wordforms设定的文件修改问题
- python 获取一个字符串所有大小写的情况
- python 文件的md5
- searchd的异常日志,跟现有索引文件有关
- 解决删除大量文件的问题 -bash: /usr/bin/sudo: Argument list too long
- python转换日志中的时间格式
- 遍历gridfs数据表