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.

Examples
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

110

So, 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.

题意:n个矩形 给你左下 右上 两点 计算矩形面积之和

题解:水

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define LL __int64
#define pii pair<int,int>
#define MP make_pair
const int N=;
using namespace std;
int n;
int x1,x2,y1,y2;
int main()
{
scanf("%d",&n);
int sum=;
for(int i=;i<=n;i++)
{
scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
sum=sum+(x2-x1+)*(y2-y1+);
}
cout<<sum<<endl;
return ;
}
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.

Examples
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的n个数一共有多少位

题解:很容易发现从(9,99,999,....)分界 随便搞一下

 /******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define LL __int64
#define pii pair<int,int>
#define MP make_pair
const int N=;
using namespace std;
LL n;
LL a[];
int main()
{
scanf("%I64d",&n);
LL jishu=;
LL exm=;
LL ans=;
a[]=;
for(int i=;i<=;i++)
a[i]=*a[i-];
a[]=;
while(n>=exm)
{
ans=ans+(exm-a[jishu]+)*jishu;
jishu++;
exm=exm*+;
}
ans=ans+(n-a[jishu]+)*jishu;
printf("%I64d\n",ans-);
return ;
}
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 massm 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.

Examples
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.

题意:w0, w1, w2, ..., w100 质量的砝码 用天平秤 m质量的东西 砝码可以放置在天平的两侧 如果可以秤出物体m 输出 YES

题解:对于w^k,系数只能取-1,0,1

/******************************
code by drizzle
blog: www.cnblogs.com/hsd-/
^ ^ ^ ^
O O
******************************/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<map>
#include<algorithm>
#include<queue>
#define LL __int64
#define pii pair<int,int>
#define MP make_pair
const int N=;
using namespace std;
LL w,m;
LL a[];
int main()
{
scanf("%I64d %I64d",&w,&m);
while(m)
{
if(m%w==)m--;
if(m%w==w-)m++;
if(m%w==)m/=w;
else
{
puts("NO");
return ;
}
}
puts("YES");
return ;
}

Codeforces Round #308 (Div. 2) A B C 水 数学的更多相关文章

  1. Codeforces Round #308 (Div. 2)B. Vanya and Books 数学

    B. Vanya and Books Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/pr ...

  2. 水题 Codeforces Round #308 (Div. 2) A. Vanya and Table

    题目传送门 /* 水题:读懂题目就能做 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  3. 数学 Codeforces Round #308 (Div. 2) B. Vanya and Books

    题目传送门 /* 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) */ #include <cstdio> #include <iostream& ...

  4. 暴力/进制转换 Codeforces Round #308 (Div. 2) C. Vanya and Scales

    题目传送门 /* 题意:问是否能用质量为w^0,w^1,...,w^100的砝码各1个称出重量m,砝码放左边或在右边 暴力/进制转换:假设可以称出,用w进制表示,每一位是0,1,w-1.w-1表示砝码 ...

  5. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  6. Codeforces Round #368 (Div. 2) C. Pythagorean Triples(数学)

    Pythagorean Triples 题目链接: http://codeforces.com/contest/707/problem/C Description Katya studies in a ...

  7. Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题

    Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...

  8. Codeforces Round #622 (Div. 2) B. Different Rules(数学)

    Codeforces Round #622 (Div. 2) B. Different Rules 题意: 你在参加一个比赛,最终按两场分赛的排名之和排名,每场分赛中不存在名次并列,给出参赛人数 n ...

  9. Codeforces Round #284 (Div. 2)A B C 模拟 数学

    A. Watching a movie time limit per test 1 second memory limit per test 256 megabytes input standard ...

随机推荐

  1. CENTOS 修改MYSQL文件到内存盘

    # 必须说明的是: # 0 内存盘的特性是断电就丢数据. # 1 对数据时效性要求高的自己做主从 # 2 重启or关机必须导出数据和开机加载数据. # 3 最好弄个脚本 开关机自己调用. # 4 简单 ...

  2. Oracle、Mysql、Sql Server语句的区别

    1.空值的处理——判断是否为空,为空时取一个值,不为空时取另一个值 1).Sql Server 中 ISNULL(check_expression,replacement_value) 解释:如果ch ...

  3. [开发笔记]-Windows Service服务相关注意事项

    注意一:报错:“本地计算机上的 *** 服务启动后停止.某些服务在未由其他服务或程序使用时将自动停止.” 该问题主要的原因是 Service服务程序中有错误. 遇到这个问题时,无论是重新安装服务,还是 ...

  4. C# TCP实现多个客户端与服务端 数据 与 文件的传输

    C#菜鸟做这个东东竟然花了快三天的时间了,真是菜,菜,菜--- 下面是我用C#写的 一个简单的TCP通信,主要的功能有: (1) 多个客户端与服务器间的数据交流 (2)可以实现群发的功能 (3)客户端 ...

  5. memcpy的用法及实现

    memcpy函数的功能是从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中,返回dest所指内存地址的起始位置. #include <string.h&g ...

  6. HDU 3336 - Count the string(KMP+递推)

    题意:给一个字符串,问该字符串的所有前缀与该字符串的匹配数目总和是多少. 此题要用KMP的next和DP来做. next[i]的含义是当第i个字符失配时,匹配指针应该回溯到的字符位置. 下标从0开始. ...

  7. mp3文件 ID3v2 帧标识的含义

    mp3文件 ID3v2 帧标识的含义 Declared ID3v2 frames The following frames are declared in this draft. 4.20 AENC ...

  8. UIkit框架之UItextfield

    1.继承链:UIcontrol:UIview:UIresponder:NSObject 2.成为第一响应者:[text becomeFirstResponder];  //让该文本成为第一响应者 3. ...

  9. sphinx 全配置

    ## 数据源src1 source src1 { ## 说明数据源的类型.数据源的类型可以是:mysql,pgsql,mssql,xmlpipe,odbc,python ## 有人会奇怪,python ...

  10. Newspaper Headline_set(upper_bound)

    Description A newspaper is published in Walrusland. Its heading is s1, it consists of lowercase Lati ...