Codeforces Round #308 (Div. 2) A B C 水 数学
2 seconds
256 megabytes
standard input
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.
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.
In a single line print the sum of all values in the cells of the table.
2
1 1 2 3
2 2 3 3
10
2
1 1 3 3
1 1 3 3
18
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 ;
}
1 second
256 megabytes
standard input
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.
The first line contains integer n (1 ≤ n ≤ 109) — the number of books in the library.
Print the number of digits needed to number all the books.
13
17
4
4
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 ;
}
1 second
256 megabytes
standard input
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.
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.
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
3 7
YES
100 99
YES
100 50
NO
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 ;
}
最新文章
- 简单设置eworkflow条件的方式
- 浏览器缓存详解:expires,cache-control,last-modified,etag详细说明
- 【转】MySQL数据类型和常用字段属性总结
- s:iterator,s:if与OGNL的嵌套使用
- DBA_Oracle LogMiner分析重做和归档日志(案例)
- [译] ASP.NET 生命周期 – ASP.NET 上下文对象(六)
- Python 入门教程 10 ---- Student Becomes the Teacher
- LVM(2)逻辑卷的扩展、缩减、快照卷
- 【编程技巧】addSubview和insertSubview的区别
- day10(闭包、import模块、函数命名空间)
- Django 自带认证功能auth模块和User对象的基本操作
- centos7下安装docker(15.7容器跨主机网络---calico)
- redis注册成window服务 标签: redis
- CPU缓存一致性协议—MESI详解
- 【java编程】运算符
- 廖雪峰Java2-2数据封装-2构造方法
- oracle 将字符串转化为数值型to_number()
- 重建索引:ALTER INDEX..REBUILD ONLINE vs ALTER INDEX..REBUILD
- ocat 资源路径-时间控件
- windows server2012部署apache项目访问后台管理系统时tomcat就停了是怎么回事