A. Vanya and Table

 

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

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个矩形,问你面积之和

转载请注明出处:寻找&星空の孩子

题目链接: http://codeforces.com/contest/552/problem/A

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include<string>
#include<map>
using namespace std;
const int MAXN = ;
int a[][]; int main()
{
int i,j,k,n,m,x1,x2,y1,y2,ans = ;
int maxx = ,maxy=,minx=,miny=;
scanf("%d",&n);
memset(a,,sizeof(a));
while(n--)
{
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
/* maxx = max(maxx,max(x1,x2));
maxy = max(maxy,max(y1,y2));
minx = max(minx,max(x1,x2));
miny = max(miny,max(y1,y2));*/
for(i = x1;i<=x2;i++)
{
for(j = y1;j<=y2;j++)
ans++;
}
}
printf("%d\n",ans);
// int ans = 0; return ;
}

B. Vanya and Books

 

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.

题意 :给你一个整数n,问你从1到n一共有多少位。比如n = 13,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13一共17位。

f[i]表示从1到10i一共有多少位,以753为例,从100到753都是3位数,所以答案就是f[2]+653*3。

转载请注明出处:寻找&星空の孩子

题目链接:http://codeforces.com/contest/552/problem/B

 #include <stdio.h>
#include <string.h>
#include <algorithm>
#include<string>
#include<map>
#define LL __int64
using namespace std;
const int MAXN = ;
LL n;
LL ans = ;
LL a[]= {,,,,,,,,,,}; int main()
{
while(~scanf("%I64d",&n))
{
ans = ;
LL i,j,k = ;
if(n<)
{
printf("%I64d\n",n);
return ;
}
for(i = ; i<=; i++)
{
k *= ;
if(n<k)
{
ans+=(n-k/+)*i;
// printf("%I64d %I64d %I64d\n",i,ans,(n-k/10+1)*i);
break;
}
/* else if(n==k)
{
ans+=(i+1);
break;
}*/
else
{
ans+=(a[i]-a[i-])*i;
}
// printf("%d %I64d\n",i,ans);
}
printf("%I64d\n",ans);
} return ;
}

C. Vanya and Scales

 

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.

要用质量为w0,w1,...,w100的砝码各1个称出重量m,砝码可以放在天平左边也可以放在右边。问是否可以称出,输出YES或NO。

如样例3,7:左边放3和物品,右边放1和9即可。

假设可以称出,则用w进制表示m,每一位上一定是0,1或w - 1,否则一定不行。

而如果某一位是w - 1则说明当前砝码跟物品放在一起,相当于给物品加上了这个砝码的重量。

我们只需要模拟这个过程,提取m的每一位然后计算即可。

转载请注明出处:寻找&星空の孩子

题目链接:http://codeforces.com/contest/552/problem/C

 #include<string.h>
#include<stdio.h>
#define LL __int64
LL w,m;
int main()
{
scanf("%I64d%I64d",&w,&m);
if(w<=)
{
printf("YES\n");
return ;
}
while(m)
{
if(!((m-)%w)) m--;
else if(!((m+)%w)) m++;
else if(m%w) {printf("NO\n");return ;}
m=m/w;
}
printf("YES\n");
return ;
}

D. Vanya and Triangles

 

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
4
0 0
1 1
2 0
2 2
output
3
input
3
0 0
1 1
2 0
output
1
input
1
1 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个点,问一共能构成多少个面积不为0的三角形。

转载请注明出处:寻找&星空の孩子

题目链接:http://codeforces.com/contest/552/problem/D

 #include<cstdio>
#include<cmath>
#include<iostream>
#define PI acos(-1.0)
using namespace std; struct Point
{
double x,y;
Point(double x=,double y=):x(x),y(y){} }; typedef Point Vector; Vector operator + (Vector A,Vector B){return Vector(A.x+B.x,A.y+B.y);} Vector operator - (Point A,Point B){return Vector(A.x-B.x,A.y-B.y);} Vector operator * (Vector A,double p){return Vector(A.x*p,A.y*p);} Vector operator / (Vector A,double p){return Vector(A.x/p,A.y/p);} bool operator < (const Point& a,const Point& b){return a.x<b.x||(a.x==b.x && a.y<b.y);} const double eps = 1e-; int dcmp(double x){if(fabs(x)<eps)return ;else return x < ? - : ;} bool operator == (const Point& a,const Point& b){return dcmp(a.x-b.x)== && dcmp(a.y-b.y)==;} double Dot(Vector A,Vector B){return A.x*B.x+A.y*B.y;}
double length(Vector A){return sqrt(Dot(A,A));}
double Angle(Vector A,Vector B){return acos(Dot(A,B)/length(A)/length(B));} double Cross(Vector A,Vector B){return A.x*B.y-B.x*A.y;}
double Area2(Point A,Point B,Point C){return Cross(B-A,C-A);} inline Point read_point(Point &P)
{
scanf("%lf%lf",&P.x,&P.y);
return P;
}
int main()
{
int n;
Point po[];
scanf("%d",&n);
for(int i=;i<n;i++)
read_point(po[i]);
if(n<){printf("0\n");return ;}
int cnt=;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
{
for(int k=j+;k<n;k++)
{
if(Area2(po[i],po[j],po[k])!=) cnt++;
}
}
}
printf("%d\n",cnt);
return ;
}

E. Vanya and Brackets

 

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

给你一个表达式,只有乘号和加号,数字都是1到9,要求加一个括号,使得表达式的值最大,问最大是多少。乘号个数<=15。

左括号一定在乘号右边,右括号一定在乘号左边,因为如果不是这样的话,一定可以调整括号的位置使表达式的值增大。这个应该不难想。

于是只要枚举括号的位置然后计算表达式即可。

转载请注明出处:寻找&星空の孩子

题目链接:http://codeforces.com/contest/552/problem/E

 #include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
const int N = ;
#define LL __int64 char fh[N],s[N];
LL num[N];
int ftop,ntop ,slen;
void calculate(){
if(fh[ftop]=='+')
num[ntop-]+=num[ntop],ntop--;
else if(fh[ftop]=='-')
num[ntop-]-=num[ntop],ntop--;
else if(fh[ftop]=='*')
num[ntop-]*=num[ntop],ntop--;
else if(fh[ftop]=='/')
num[ntop-]/=num[ntop],ntop--;
ftop--;
}
void countfuction(int l,int r){
ftop=;ntop=;
int flagNum=;
LL ans=;
for(int i=; i<=slen; ++i){ if(i!=slen&&(s[i]>=''&&s[i]<='')){
ans=ans*+s[i]-'';
flagNum=;
}
else{
if(flagNum)num[++ntop]=ans; flagNum=; ans=;
if(i==slen)break;
if(s[i]=='+'||s[i]=='-'){
while(ftop&&fh[ftop]!='(') calculate();
fh[++ftop]=s[i];
}
else if(s[i]=='*'&&i==r){
while(ftop&&fh[ftop]!='(') calculate(); ftop--;
while(ftop&&(fh[ftop]=='*'||fh[ftop]=='/')) calculate();
fh[++ftop]=s[i];//printf("# ");
}
else if(s[i]=='*'||i==l){
while(ftop&&(fh[ftop]=='*'||fh[ftop]=='/')) calculate();
fh[++ftop]=s[i];
if(i==l)
fh[++ftop]='(';
}
}
}
while(ftop) calculate(); }
int main(){ while(scanf("%s",s)>){
LL ans=;
int id[],k=;
for(int i=strlen(s); i>=; i--)
s[i+]=s[i];
s[]=''; s[]='*';
slen=strlen(s);
s[slen]='*'; s[slen+]=''; s[slen+]='\0';
slen=strlen(s);
for(int i=; i<slen; i++)
if(s[i]=='*')
id[k++]=i; for(int i=; i<k-; i++)
for(int j=i+; j<k; j++){
countfuction(id[i],id[j]);
if(num[]>ans)
ans=num[];
}
printf("%I64d\n",ans);
}
}

Codeforces Round #308 (Div. 2)的更多相关文章

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

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

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

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

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

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

  4. Codeforces Round #308 (Div. 2) D. Vanya and Triangles 水题

    D. Vanya and Triangles Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/55 ...

  5. Codeforces Round #308 (Div. 2) C. Vanya and Scales dfs

    C. Vanya and Scales Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/552/p ...

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

  7. Codeforces Round #308 (Div. 2) A. Vanya and Table 暴力

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

  8. Codeforces Round #308 (Div. 2)----C. Vanya and Scales

    C. Vanya and Scales time limit per test 1 second memory limit per test 256 megabytes input standard ...

  9. Codeforces Round #308 (Div. 2) A B C 水 数学

    A. Vanya and Table time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. .Net持续集成 —— Jenkins+Git+WebDeploy

    由于某些历史问题,最近终于可以从java中解脱出来,继续耕耘.Net了,第一步就是把之前的java项目翻成.net.之前已经实现过一次,翻起来还是比较快的(当然基础架构/实体模型已经重新思考并改进), ...

  2. Windows 10 IoT Core 17133 for Insider 版本更新

    今天,微软发布了Windows 10 IoT Core 17133 for Insider 版本更新,本次更新只修正了一些Bug,没有发布新的特性.用户可以登录Windows Device Porta ...

  3. [转]语言模型训练工具SRILM

    SRILM是一个建立和使用统计语言模型的开源工具包,从1995年开始由SRI 口语技术与研究实验室(SRI Speech Technology and Research Laboratory)开发,现 ...

  4. 封装一个简易版的ajax操作对象

    /** * 发送ajax请求 * @type {Object} * 使用方法如下: * $ajax.request( * method: "post", //请求方式 * url: ...

  5. 第46节:Java当中的常量池

    Java当中的常量池 在Java虚拟机jvm中,内存分布为:虚拟机堆,程序计数器,本地方法栈,虚拟机栈,方法区. 程序计数器是jvm执行程序的流水线,是用来存放一些指令的,本地方法栈是jvm操作系统方 ...

  6. ansible中include_tasks和import_tasks

    简介 本文主要总结下ansible里task调用的方法有哪些和它们的主要区别 ​随着要管理的服务不断增多,我们又没将task放到roles里,会发现playbook文件越来越大,内容也越来越多,管理起 ...

  7. java,让debug出色

    虽然我们不喜欢bug,但是bug永远都存在.虽然我们牛逼,但是仍然有不知道的东西,解决不了的问题.so,还得借助工具,让咱效率提起来扛扛的.解决的问题如是:由于某种原因,其他系统发送的mq,我这边说没 ...

  8. postgresql 日常sql

    查看服务进程: select pid,usename,client_addr,client_port from pg_stat_activity;   查看当前数据库实例的版本:  select ve ...

  9. SWIG 基本概念和入门

    C 和 C++ 被公认为(理当如此)创建高性能代码的首选平台.对开发人员的一个常见要求是向脚本语言接口公开 C/C++ 代码,这正是 Simplified Wrapper and Interface ...

  10. 原生端与服务器通过sessionid实现session共享以及登录验证

    注:原生端与服务器建立连接时产生的sessionid会变,跟上一次的不一样,为了保证sessionid一样,所以第一次服务器需要把sessionid返回给原生端,下一次与服务端会话时,原生端需要把这个 ...