Codeforces Round #308 (Div. 2)题解

伺服电机入门01 编码器输出 旋转信号 , 接收端: 使用ADC 捕捉旋转信号 ,转成数字信号,驱动器得到数字处理, 因为信号量是模拟信号, mcu mpu 等芯片通常内部处理是数字,通过adc 得到数字cpu 才能识别 传输过来的pos 等信息。IPM 芯片示例, IRAM256A 这个芯片已经停产,有换新的,,下面示例来自stmbl 高功率方案,4 步进电机 有全步控制,半步控制 ,微步控制,FOC控制,步进电机也是可以做伺服系统的。以下面几种信号是可以细分,也就是通过细分增加编码器的分辨率, 阅读详情

第二天补的

并不都是自己写的

参考了别人的题解

感觉这次cf题意好懂

就是做起来嘛。。

毕竟我还太弱。。

只为落实微笑


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 ≤ 1001 ≤ 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.



题意:给两个点坐标算矩形面积之和



#include "iostream"
#include "cstdio"
#include "cmath"
#include "algorithm"
using namespace std;
int main(int argc, char const *argv[])
{
	int n, a, b, c, d;
	cin >> n;
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		cin >> a >> b >> c >> d;
		ans += abs(c - a + 1) * abs(d - b + 1);
	}
	cout << ans << endl;
	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.



题意:给一个n判断1~n有多少个数 eg: 13有17个数 分别是:1,2,3,4,5,6,7,8,9,1,0,1,1,1,2,1,3


思路:一个数组保存个数 另外加一下零头多少个就好了


AC代码:



#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "cmath" 
using namespace std;
 
int n;
long long f[12];
long long t[12];
int main() {
    cin >> n;
    t[1] = 10;
    for (int i = 2; i <= 10; i++)
        t[i] = t[i - 1] * 10;
    f[1] = 11;
    for (int i = 2; i <= 10; i++)
        f[i] = f[i - 1] + (t[i] - t[i - 1]) * i + 1;
    long long ans;
    long long base;
    for (int i = 0; i <= n; i++) {
        if (t[i] > n) {
            base = i - 1;
            break;
        }
    }
    ans = f[base] + (n - t[base]) * (base + 1);
    cout << ans << endl;
    return 0;
}<span style="color:#33cc00;">
</span>

我的代码():


判错是test5 可是我本地和oj上结果不一样  本地上的结果就是对的。。  奇怪。。


#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "queue"
#include "cmath"
using namespace std;
long long num[12] = {0};
void init()
{
    for(int i = 1; i <= 11; ++i)
        num[i] = num[i - 1] + 9 * pow(10, i - 1) * i;
}
int main(int argc, char const *argv[])
{
    int n;
    init();
    while(cin >> n) {
        int x = n, n_num = 0;
        while(x / 10) {
            n_num++;
            x /= 10;
        }
        if(n_num == 0) {
            printf("%d\n", n);
            return 0;
        }
        long long ans = num[n_num];
        ans += (n - pow(10, n_num) + 1) * (n_num + 1);      
        cout << ans << endl;
    }
    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 ≤ 1091 ≤ 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的砝码乘出质量m,砝码可放天平左可放天平右

思路:假设可以称出,用w进制表示m,每一位上一定是0, 1,  w - 1, 否则就是NO,如果某一位是w-1则说明这个砝码跟物品摆在同一边,

对m的每一位模拟这个过程

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
using namespace std;
int main(int argc, char const *argv[])
{
	int n, m;
	cin >> n >> m;
	if(n == 3) {
		cout << "YES" << endl;
		return 0;
	}
	while(m) {
		int z = m % n;
		if(z <= 1)
			m /= n;
		else if(z == n - 1)
			m = m / n + 1;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	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
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个坐标,问能构成几个三角形

嗯。。还是看题解。。

思路:总方案数为n^3之和(数学公式),枚举每一个点,计算这个点与其他所有点的斜率,三点共线则斜率会相等,减去相等斜率m个点m^2之和

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "vector"
#include "cmath"
using namespace std;
const double inf = 1e10;
const double eps = 1e-8;
typedef long long ll;
struct point
{
	/* data */
	int x, y;
	point() {};
	point(int a, int b): x(a), y(b) {}
};
int n;
point p[2005];
int main(int argc, char const *argv[])
{
	cin >> n;
	for(int i = 0; i < n; ++i)
		cin >> p[i].x >> p[i].y;
	if(n < 3) {
		cout << 0 << endl;
		return 0;
	}
	ll tot = (ll)n * (n - 1) * (n - 2) / 6;
	ll sum = 0;
	vector<double> ans;
	for(int i = 0; i < n; ++i) {
		ans.clear();
		for(int j = i + 1; j < n; ++j) {
			int dx = p[j].x - p[i].x;
			int dy = p[j].y - p[i].y;
			double k;
			if(dx == 0) k = inf;
			else if(dy == 0) k = 0.0;
			else k = (double)dy / (double)dx;
			ans.push_back(k);
		}
		sort(ans.begin(), ans.end());
		double num = ans[0];
		int cnt = 0;
		for(int j = 0; j < ans.size(); ++j)
			if(fabs(ans[j] - num) < eps) cnt++;
			else {
				sum += (ll)cnt * ((ll)cnt - 1ll) / 2;
				cnt = 1;
				num = ans[j];
			}
		sum += (ll)cnt * ((ll)cnt - 1ll) / 2;
	}
	cout << tot - sum << endl;
	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).



题意:给出一个表达式只含有加号+和乘号*,数字是1~9,让你加一个括号,使得表达式值最大,看这个就知道肯定用栈(说的好像我会一样)

思路:左括号在乘号右边,右括号在乘号左边保证最大。枚举括号位置并计算。

AC代码:

#include "iostream"
#include "cstdio"
#include "cstring"
#include "algorithm"
#include "stack"
#include "vector"
#include "string"
using namespace std;
typedef long long ll;
int n;
string str;
vector<int> pos;
stack<char> sc;
stack<ll> sn;

ll tworesult(ll a, ll b, char c) {
	return (c == '*') ? a * b : a + b;
}
void cal() {
	char t = sc.top();
	sc.pop();
	ll a = sn.top();
	sn.pop();
	ll b = sn.top();
	sn.pop();
	sn.push(tworesult(a, b, t));
}
ll expression(string s) {
	for(int i = 0; i < s.length(); ++i) {
		char c = s[i];
		if(isdigit(c)) sn.push(c - '0');
		else if(c == '(') sc.push(c);
		else if(c == ')') {
			while(sc.top() != '(') cal();
			sc.pop(); 
		}else {
			if(c == '+') {
				while(!sc.empty() && sc.top() == '*') cal();
				sc.push(c);
			}else sc.push(c);
		}
	}
	while(!sc.empty()) cal();
	return sn.top();
}
int main(int argc, char const *argv[])
{
	cin >> str;
	n = str.size();
	pos.push_back(-1);
	for(int i = 1; i < n; i += 2)
		if(str[i] == '*') pos.push_back(i);
	pos.push_back(n);
	int len = pos.size();
	ll ans = 0;
	for(int i = 0; i < len - 1; ++i)
		for(int j = i + 1; j < len; ++j) {
			string s = str;
			s.insert(pos[i] + 1, 1, '(');
			s.insert(pos[j] + 1, 1, ')');
			ans = max(ans, expression(s));
		}
	cout << ans << endl;
	return 0;
}



测风数据垂直外推(原理及Windowgrapher操作示范) 垂直外推 阅读详情

相关推荐

QML从入门到实战 - 完整学习路线

想入门 QML 开发?来 “从零开始学 QML” 专栏,海量源码 + 实战案例 + 大型项目拆解,手把手教你搞定跨平台 UI 设计,小白也能轻松掌握!

BenBierBa的博客 3288

Day5-T4

原题目   Describe:最小生成树加权   code: #include<bits/stdc++.h> #define INF 214748364 #define eps 1e-9 #define rep1(a,b) for(register long long i=(a);i<=(b);i++) #define rep2(a,b) for(registe...

weixin_30920597的博客 119

NR PUCCH() PUCCH format 0/1

NR中PUCCH物理信道用来发送上行控制信息Uplink Control Information(UCI),当然UCI也可以在PUSCH上发送。UCI 内容包括:CSI,HARQ ACK/NACK ,SR 及上述三者的组合信息。 那先看下PUCCH format ,序列的生成及资源映射的相关内容。 NR中支持5种格式PUCCH,根据PUCCH format占用时域符号长度分为短PUCCH(1-2个符号,PUCCH 0/2)和长PUCCH(4-14个符号,PUCCH1/3/4)。使用短PUCCH 能够支

asd199086的博客 6029

A sequence of numbers (入门题-数学)

A sequence of numbers                                                                                   Time Limit: 1 Seconds    Memory Limit: 32 Mbyte 题目描述:       Xinlv wrote some sequences on t

2569

Codeforces Round #308 (Div. 2)

再次厚颜无耻地宣传一发:新博客http://shijieyywd.com/?p=99这次cf真是发挥的有点醉,下次有div1我都不敢做了。A. Vanya and Table给你n个矩形,问你面积之和。是面积之和不是面积并,直接算。然而我这个傻逼交错文件了WA了一发233333。#include <bits/stdc++.h>using namespace std;int n; int main()

Shion的专栏 1529

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

题目传送门 1 /* 2 水题:读懂题目就能做 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #include <cmath> 9 #i...

weixin_30289831的博客 70

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

http://www.codeforces.com/problemset/problem/552/B题意:给你一个数N,问你从1到N所有的数的数字位数之和为多少。 解法: 不难看出,数对应的数字位数分别为: 1-9 1 10-99 2 100-999 3 …

Accepted丶 394

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

题目传送门 1 /* 2 水题:求总数字个数,开long long竟然莫名其妙WA了几次,也没改啥又对了:) 3 */ 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 #include <cstring> 8 #in...

weixin_33807284的博客 76

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

题目链接:http://codeforces.com/contest/552/problem/B 题意:就是求有几个数字; eg:13:1 2 3 4 5 6 4 7 8 9 1 0 1 1 1 2 1 3 一共17个数字#include <iostream>using namespace std; long long a[12]={0,9,99,999,9999,99999,999999

代码改变世界 869

Codeforces Round #308 (Div. 2) 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

lljjccsskk的专栏 348

Codeforces Round #308 (Div. 2) A、B

552A - Vanya and Table 这题没什么好说的了,题目读懂了直接模拟就可以了。#include <stdio.h> #include <string.h> #include <algorithm> #include <iostream> using namespace std; int g[105][105]; int gao(int x, int y, int xx, int y

Freeway的博客 693

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

题目链接:http://codeforces.com/contest/552/problem/A hint: 就是求几个矩形的面积#include <iostream> #include <cmath> using namespace std; struct point { int x; int y; }a[2]; int main() { int m; while

代码改变世界 834

Codeforces Round #308 (Div. 2) 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 ...

loooooog的博客 180
上一篇: ssanf
下一篇: NOJ1057 封杀病毒(pow & sqrt函数的原型)
GKHack
博客等级 码龄11年 48粉丝 291原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值