PassThePAT


  • 首页

  • 标签

  • 分类

  • 归档

  • 搜索

1068 Find More Coins

发表于 2020-05-31

1067 Sort with Swap(0, i)

发表于 2020-05-31

1066 Root of AVL Tree

发表于 2020-05-31

1065 A+B and C (64bit)

发表于 2020-05-31

1064 Complete Binary Search Tree

发表于 2020-05-31

1063 Set Similarity

发表于 2020-05-31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <cstdio>
#include <vector>
#include <set>
using namespace std;
int main() {
int n, m, k, temp, a, b;
scanf("%d", &n);
vector<set<int>> v(n);
for(int i = 0; i < n; i++) {
scanf("%d", &m);
set<int> s;
for(int j = 0; j < m; j++) {
scanf("%d", &temp);
s.insert(temp);
}
v[i] = s;
}
scanf("%d", &k);
for(int i = 0; i < k; i++) {
scanf("%d %d", &a, &b);
int nc = 0, nt = v[b-1].size();
for(auto it = v[a-1].begin(); it != v[a-1].end(); it++) {
if(v[b-1].find(*it) == v[b-1].end())
nt++;
else
nc++;
}
double ans = (double)nc / nt * 100;
printf("%.1f%%\n", ans);
}
return 0;
}

1062 Talent and Virtue

发表于 2020-05-31

题目要求,输入N,参与排名的人数,L,参与排名的及格分数要求,H,参与排名优秀非分数要求。德与才均不低于H的成为圣人,按总分由高到低排列(will be ranked in non-increasing order according to their total grades.)才低于H,而德不低于者成为君子,德才均低于H,但德不低于才的成为愚人,剩下的称为小人,按照圣人君子愚人小人排列,同一种人按照总分非递增排列。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
struct node {
int num, de, cai;
};
int cmp(struct node a, struct node b) {
if ((a.de + a.cai) != (b.de + b.cai))
return (a.de + a.cai) > (b.de + b.cai);
else if (a.de != b.de)
return a.de > b.de;
else
return a.num < b.num;
}
// 为什么这里是>而不是>=呢,因为总分相同,按德分,德分同,看序号。所以=的情况会下放到下一个判断语句里去。
int main() {
int n, low, high;
scanf("%d %d %d", &n, &low, &high);
vector<node> v[4];
node temp;
int total = n;
for (int i = 0; i < n; i++) {
scanf("%d %d %d", &temp.num, &temp.de, &temp.cai);
if (temp.de < low || temp.cai < low)
total--;
else if (temp.de >= high && temp.cai >= high)
v[0].push_back(temp);
else if (temp.de >= high && temp.cai < high)
v[1].push_back(temp);
else if (temp.de < high && temp.cai < high && temp.de >= temp.cai)
v[2].push_back(temp);
else
v[3].push_back(temp);
}
printf("%d\n", total);
for (int i = 0; i < 4; i++) {
sort(v[i].begin(), v[i].end(), cmp);
for (int j = 0; j < v[i].size(); j++)
printf("%d %d %d\n", v[i][j].num, v[i][j].de, v[i][j].cai);
}
return 0;
}

1061 Dating

发表于 2020-05-31

1060 Are They Equal

发表于 2020-05-31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n, p = 0, q = 0;
char a[10000], b[10000], A[10000], B[10000];
scanf("%d%s%s", &n, a, b);
int cnta = strlen(a), cntb = strlen(b);
for(int i = 0; i < strlen(a); i++) {
if(a[i] == '.') {
cnta = i;
break;
}
}
for(int i = 0; i < strlen(b); i++) {
if(b[i] == '.') {
cntb = i;
break;
}
}
// cnta和cntb为a和b两个字符串的小数点下标,初始值为字符串长度
int indexa = 0, indexb = 0;
while(a[p] == '0' || a[p] == '.') p++;
while(b[q] == '0' || b[q] == '.') q++;
// p和q为非0非小数点的下标
if(cnta >= p)
cnta = cnta - p;
else
cnta = cnta - p + 1;
if(cntb >= q)
cntb = cntb - q;
else
cntb = cntb - q + 1;
if(p == strlen(a))
cnta = 0;
if(q == strlen(b))
cntb = 0;
while(indexa < n) {
if(a[p] != '.' && p < strlen(a))
A[indexa++] = a[p];
else if(p >= strlen(a))
A[indexa++] = '0';
p++;
}
while(indexb < n) {
if(b[q] != '.' && q < strlen(b))
B[indexb++] = b[q];
else if(q >= strlen(b))
B[indexb++] = '0';
q++;
}
// index从0到n-1保存有效数字(有效数字不够用0补)
// b[q] != '.'是有必要的,比如10.或则是10.1
if(strcmp(A, B) == 0 && cnta == cntb)
printf("YES 0.%s*10^%d", A, cnta);
else
printf("NO 0.%s*10^%d 0.%s*10^%d" , A, cnta, B, cntb);
return 0;
}

1059 Prime Factors

发表于 2020-05-31
1…91011…16

e5

158 日志
5 标签
© 2022 e5
由 Hexo 强力驱动
|
主题 — NexT.Mist v5.1.4