A. Vanya and Table
题目链接:codeforces552A
题意:
给出n个矩形,求总面积 ,输入x1, y1, x2, y2 代表矩形左下点和右上点
题解: 模拟
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, area = 0;
cin >> n;
while(n--){
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
area += abs(x2 - x1 + 1) * abs(y2 - y1 + 1);
}
cout << area << endl;
return 0;
}
B. Vanya and Books(思维)
题目链接:codeforces 552B
题意:
问从1 到 n 的数据位数之和为多少, 比如 12 就是两位
题解:
1-9都是一位 10-99都是两位 100 - 999 都是三位........
#include<bits/stdc++.h>
using namespace std;
int main(){
long long n,ans = 0,m = 1;
scanf("%lld",&n);
while(n - m >= 0){
ans += n - m + 1;
m = m * 10;
}
printf("%lld\n",ans);
return 0;
}
C. Vanya and Scales(思维)
题目链接: codeforces552C
题意:
给101个砝码(砝码重量为 w^0, w^1, w^2 .......w^100, 各一个), 一个重量为 m 的重物,问能否使称两边相等。
题解:
#include<bits/stdc++.h>
using namespace std;
int main(){
int w, m;
cin >> w >> m;
while(m % w == 0 || (m + 1) % w == 0 || (m - 1) % w == 0){
if(m % w == 0){
m = m / w;
}
else if((m - 1) % w == 0){
m = (m - 1) / w;
}
else if((m + 1) % w == 0){
m = (m + 1) / w;
}
if(m == 0){
break;
}
}
if(m != 0){
cout << "NO" << endl;
}
else{
cout << "YES" << endl;
}
return 0;
}
D. Vanya and Triangles(三点共线,三角形个数)
题目链接 codeforces 552D
题意:
给出n个点,判断有多少个不同的三角形
题解
当三点不共线时,就是一个三角形
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
int x, y;
}a[2005];
int check(node b, node c, node d){ // 叉乘相乘不等于0
return (b.x - c.x) * (d.y - c.y) - (d.x - c.x) * (b.y - c.y);
}
int main(){
while(1){
int n;
cin >> n;
int ans = 0;
for(int i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
}
for(int i = 1; i <= n; i++){
for(int j = i+1; j <= n; j++){
for(int k = j+1; k <= n; k++){
if(check(a[i], a[j], a[k]) != 0){
ans++;
}
}
}
}
cout << ans << endl;
}
return 0;
}