#291 div.2

A.水题 数字翻转,将每一位大于等于5的数字t翻转成9-t,注意不要有前导0,且翻转后数字的位数不变(即9999->9000...刚开始以为应该翻转成0了= =)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 using namespace std;
 6 int main()
 7 {
 8     char x[20];
 9     cin >> x;
10     int len = strlen(x);
11     for(int i = 0; i < len; i++)
12         if(x[i] >= ‘5‘) x[i] = ‘9‘ - x[i] + ‘0‘;
13     if(x[0] == ‘0‘) x[0] = ‘9‘;
14     cout << x << endl;
15     return 0;
16 }
17 #include<iostream>
18 #include<cstdio>
19 #include<cstdlib>
20 #include<cstring>
21 using namespace std;
22 int main()
23 {
24     char x[20];
25     cin >> x;
26     int len = strlen(x);
27     for(int i = 0; i < len; i++)
28         if(x[i] >= ‘5‘) x[i] = ‘9‘ - x[i] + ‘0‘;
29     if(x[0] == ‘0‘) x[0] = ‘9‘;
30     cout << x << endl;
31     return 0;
32 }

B.水题 斜率,每输入一个坐标(xi,yi)求出该点与标准点连线的斜率并记入数组k[]中,排序(sort),去重(unique);

NOTE:斜率注意的基本问题---斜率为无穷大与0时的特判;

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<algorithm>
 6 using namespace std;
 7 const int maxn = 1010;
 8 int main()
 9 {
10     int n, cnt1 = 0, cnt2 = 0;
11     double x0, y0, x, y;
12     double k[maxn];
13     scanf("%d%lf%lf", &n, &x0, &y0);
14     for(int i = 0; i < n; i++)
15     {
16         scanf("%lf%lf", &x, &y);
17         if(x-x0 == 0) {cnt1++; k[i] = 0; continue;}
18         if(y-y0 == 0) {cnt2++; k[i] = 0; continue;}
19         k[i] = (y-y0)/(x-x0);
20     }
21     sort(k, k+n);
22     int ans = unique(k, k+n) - k;
23     if(cnt1 && cnt2) ans++;
24     cout << ans << endl;
25     return 0;
26 }

时间: 2025-01-15 06:53:29

#291 div.2的相关文章

hash+set Codeforces Round #291 (Div. 2) C. Watto and Mechanism

题目传送门 1 /* 2 hash+set:首先把各个字符串的哈希值保存在set容器里,然后对于查询的每一个字符串的每一位进行枚举 3 用set的find函数查找是否存在替换后的字符串,理解后并不难.另外,我想用64位的自然溢出wa了,不清楚 4 */ 5 /************************************************ 6 * Author :Running_Time 7 * Created Time :2015-8-5 13:05:49 8 * File N

Codeforces Round #291 (Div. 2) E - Darth Vader and Tree (DP+矩阵快速幂)

这题想了好长时间,果断没思路..于是搜了一下题解.一看题解上的"快速幂"这俩字,不对..这仨字..犹如醍醐灌顶啊...因为x的范围是10^9,所以当时想的时候果断把dp递推这一方法抛弃了.我怎么就没想到矩阵快速幂呢.......还是太弱了..sad..100*100*100*log(10^9)的复杂度刚刚好. 于是,想到了矩阵快速幂后,一切就变得简单了.就可以把距离<=x的所有距离的点数都通过DP推出来,然后一个快速幂就解决了. 首先DP递推式很容易想到.递推代码如下: for(

Codeforces Round #291 (Div. 2)

A 题意:给出变换规则,单个数字t可以变成9-t,然后给出一个数,问最小能够变成多少. 自己做的时候理解成了不能输出前导0,但是题目的本意是不能有前导0(即最高位不能是0,其余位数按照规则就好) 555555---读题仔细o(╯□╰)o 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 char

C. Watto and Mechanism 字典树 Codeforces Round #291 (Div. 2)

C. Watto and Mechanism time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Watto, the owner of a spare parts store, has recently got an order for the mechanism that can process strings in a ce

Codeforces #291 (Div. 2) D. R2D2 and Droid Army(RMQ+二分)

题意: 有n*m的矩阵,然后你有k发子弹.现在你可以朝着任意列发射子弹,每一发子弹都会使该列上的数值-1,最小减少到0. 现在问你连续最长的行数,在k发子弹内,使得这些行上的数值全部为0. 思路: 简单的二分枚举最长行数区间,每个区间的最大值决定了要发射的子弹数,所以是RMQ问题,当然这里的枚举全部枚举,用尺取法也可以. //889 ms #include<cstdio> #include<algorithm> #include<cstring> #include<

Codeforces Round #291 (Div. 2)解题报告A.B.C.D

A - Chewbaсca and Number 大于4的倒置,小于等于4的不倒置.注意第一位如果是9则不倒置. 代码如下: #include <iostream> #include <string.h> #include <math.h> #include <queue> #include <algorithm> #include <stdlib.h> #include <map> #include <set>

Codeforces Round #291 (Div. 2)——B&lt;set&gt;—— 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 stormtro

Codeforces Round #291 (Div. 2)(B)

水题但是WA2发了,要特别考虑斜率不存在的情况,最后的答案就是斜率不同的数目,set一下 #include<cstdio> #include<cstring> #include <iostream> #include<queue> #include <cmath> #include <set> using namespace std; const int maxn=65000+10; const int INF=1<<30

Codeforces Round #291 (Div. 2)(A)

看一眼就知道的题目往往还要再看看题意....不然白白WA后悔死了 #include<cstdio> #include<cstring> #include <iostream> #include<queue> #include <cmath> using namespace std; const int maxn=65000+10; const int INF=1<<30; typedef long long LL; int main(