A. Chewbaсca and Number
对于给定的一个正整数n(1<=n<=10^18),我们可以将这个数的某些位翻转,所谓翻转是,将数字t用数字9-t替代。经过某些替换后,我们所能得到的最小正整数是多少。题目还说数字不能以0开头,所以当9为第一个数字时,是不能进行替换的。当然,也可能有其他的理解,不过命题者的意思是这样的。其他的情况就让数字尽可能小就行了。
/*************************************************************************
> File Name: a.cpp
> Author: gwq
> Mail: gwq5210@qq.com
> Created Time: 2015年04月28日 星期二 15时49分41秒
************************************************************************/#include <cmath>#include <ctime>#include <cctype>#include <climits>#include <cstdio>#include <cstdlib>#include <cstring>#include <map>#include <set>#include <queue>#include <stack>#include <string>#include <vector>#include <sstream>#include <iostream>#include <algorithm>#define INF (INT_MAX / 10)#define clr(arr, val) memset(arr, val, sizeof(arr))#define pb push_back#define sz(a) ((int)(a).size())usingnamespacestd;
typedefset<int> si;
typedefvector<int> vi;
typedefmap<int, int> mii;
typedeflonglong ll;
constdouble esp = 1e-5;
#define N 20char str[N];
int main(int argc, char *argv[])
{
while (scanf("%s", str) != EOF) {
for (int i = 0; str[i]; ++i) {
int x = str[i] - '0';
if (!i && str[i] == '9') {
continue;
}
if (9 - x < x) {
str[i] = 9 - x + '0';
}
}
printf("%s\n", str);
}
return0;
}
B. Han Solo and Lazer Gun
一个二维的坐标系,某一个点上有机抢手,其他的点上有敌人,每发射一颗炮弹,就可以将整个直线上的所有敌人都消灭,即使在同一个点上有许多敌人。只需要枚举就行了。记录那些点上的敌人已经被消灭过了。
判断三点在不在一条直线上,这里我使用的是最原始的斜率,注意斜率为0,和斜率不存在的情况。同样可以使用三角形的有向面积,有向面积为0,表明在同一条直线上。
#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>#include <iostream>#include <cstring>#include <queue>#include <stack>#include <map>#include <set>usingnamespacestd;
#define N 1010constdouble esp = 1e-6;
struct Point {
int x, y;
Point() {
}
Point (int xx, int yy) {
x = xx;
y = yy;
}
int input(void)
{
returnscanf("%d%d", &x, &y);
}
void print(void)
{
printf("%d %d\n", x, y);
}
}pt[N], gun;
int vis[N];
int gcd(int a, int b)
{
return b == 0 ? a : gcd(b, a % b);
}
int check(Point u, Point v)
{
int x, y;
x = u.x;
y = u.y;
u.x = x / gcd(x, y);
u.y = y / gcd(x, y);
x = v.x;
y = v.y;
v.x = x / gcd(x, y);
v.y = y / gcd(x, y);
if (u.x == v.x && u.x == 0) {
return1;
}
if (u.y == v.y && u.y == 0) {
return1;
}
if (u.x == v.x && u.y == v.y) {
return1;
}
u.x = -u.x;
u.y = -u.y;
if (u.x == v.x && u.y == v.y) {
return1;
}
return0;
}
int main(int argc, char *argv[])
{
int n;
while (scanf("%d", &n) != EOF) {
gun.input();
for (int i = 0; i < n; ++i) {
pt[i].input();
}
memset(vis, 0, sizeof(vis));
int cnt = 0;
for (int i = 0; i < n; ++i) {
if (vis[i]) {
continue;
}
vis[i] = 1;
int flag = 0;
for (int j = 0; j < n; ++j) {
if (i == j || vis[j]) {
continue;
}
Point x1(pt[i].x - gun.x, pt[i].y - gun.y);
Point x2(pt[j].x - gun.x, pt[j].y - gun.y);
if (check(x1, x2)) {
vis[j] = 1;
//pt[j].print();
++flag;
}
}
//printf("...\n\n");
++cnt;
}
printf("%d\n", cnt);
}
return0;
}