今天开始CF - ABC 计划,开始慢慢补 之前的题目,不过C D E 能不能搞定我也不知道,看情况吧、、、
链接:http://codeforces.com/contest/514
A. Chewbaсca and Number
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digitt means replacing it with digit
9 - t.
Help Chewbacca to transform the initial number x to the minimum possiblepositive number by inverting some (possibly, zero) digits. The decimal representation of the final number
shouldn't start with a zero.
The first line contains a single integer x(1 ≤ x ≤ 1018) — the number that Luke Skywalker gave to Chewbacca.
Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes.
27
22
4545
4444
输入一个字符串,判断每一位数 t 经过9 - t 之后,看能否是数字变小,而且不能含前导 0 。
#include <stdio.h> #include <algorithm> #include <string.h> #include <math.h> using namespace std; char s[20]; int main() { while(~scanf("%s",s)) { int len = strlen(s); if(s[0] - '0' >= 5 && (s[0] - '0' != 9)) printf("%d",9 - (s[0] - '0')); else printf("%d",s[0]-'0'); for(int i = 1; i < len; i ++) { if(s[i] - '0' >= 5) printf("%d",9 - (s[i] - '0')); else printf("%d",s[i]-'0'); } printf("\n"); } }
B. Han Solo and Lazer Gun
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates(x, y)
on this plane.
Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point(x0, y0). In one shot it can can destroy all the
stormtroopers, situated on some line that crosses point(x0, y0).
Your task is to determine what minimum number of shots Han Solo needs to defeat all the stormtroopers.
The gun is the newest invention, it shoots very quickly and even after a very large number of shots the stormtroopers don't have enough time to realize what's happening and change their location.
The first line contains three integers n,x0 и
y0 (1 ≤ n ≤ 1000, - 104 ≤ x0, y0 ≤ 104)
— the number of stormtroopers on the battle field and the coordinates of your gun.
Next n lines contain two integers each
xi,
yi ( - 104 ≤ xi, yi ≤ 104)
— the coordinates of the stormtroopers on the battlefield. It is guaranteed that no stormtrooper stands at the same point with the gun. Multiple stormtroopers can stand at the same point.
Print a single integer — the minimum number of shots Han Solo needs to destroy all the stormtroopers.
4 0 0 1 1 2 2 2 0 -1 -1
2
2 1 2 1 1 1 0
1
Explanation to the first and second samples from the statement, respectively:
需要多少条经过指定点的线,才能使所有的点都被覆盖、、
需要注意 精度的问题,一开始 我用的double 结果搞到 abs(point[i].k-
point[j].k) <
0.00000001 还是不行,其实这里有一个更好的解法就是
(point[i].x-x)*(point[j].y-
y)==
(point[j].x- x)*(point[i].y-
y), 这样可以解决精度问题。
我用flag 表示是否是和指定的点在同一条垂直x 轴的直线上
这里给出第24 组数据,输出答案为 2
2 -10000 -10000
9998 9999
9999 10000
代码如下(可能会有没用的代码)
#include <stdio.h> #include <iostream> #include <algorithm> #include <string.h> #include <math.h> #include <queue> #include <vector> #include <map> using namespace std; #define N 1010 struct node { int x, y; bool vis; }point[N]; int main() { int n, x, y; while(~scanf("%d%d%d",&n, &x, &y)) { for(int i = 1; i <= n; i ++) { scanf("%d%d",&point[i].x, &point[i].y); point[i].vis = false; } int cnt = 0; bool flag = false; for(int i = 1;i <= n; i ++) { if(point[i].x == x) { point[i].vis = true; flag = true; continue; } if(!point[i].vis) { point[i].vis = true; for(int j = 1; j <= n; j ++) { if(point[j].vis) continue; if(point[j].x == x) { point[j].vis = true; flag = true; } else if((point[i].x -x)*(point[j].y - y) == (point[j].x - x)*(point[i].y - y)) { point[j].vis = true; // printf("%d -----------\n", j); } } cnt ++; //printf("%d --- %d\n",i, cnt); } } if(flag) cnt ++; printf("%d\n", cnt); } }