AtCoder Beginner Contest 106 ABCD

A - Garden

Problem Statement

There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)

What is the area of this yard excluding the roads? Find it.

Note

It can be proved that the positions of the roads do not affect the area.

Constraints

  • A is an integer between 2 and 100 (inclusive).
  • B is an integer between 2 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

A B

Output

Print the area of this yard excluding the roads (in square yards).


Sample Input 1

Copy

2 2

Sample Output 1

Copy

1

In this case, the area is 1 square yard.


Sample Input 2

Copy

5 7

Sample Output 2

Copy

24

In this case, the area is 24 square yards.

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7
 8 int main(){
 9     int a,b;
10     cin >> a >> b;
11     printf("%d\n",a*b-(a+b-1));
12     return 0;
13 }

B - 105

Problem Statement

The number 105 is quite special - it is odd but still it has eight divisors. Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

Constraints

  • N is an integer between 1 and 200 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the count.


Sample Input 1

Copy

105

Sample Output 1

Copy

1

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.


Sample Input 2

Copy

7

Sample Output 2

Copy

0

1 has one divisor. 35 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7
 8 int main(){
 9     int n;
10     cin >> n;
11     int ans = 0;
12     for(int i = 105; i <= n; i ++) {
13         if(i&1) {
14             int cnt = 0;
15             for(int j = 1; j <= n; j ++) if(i%j==0) cnt++;
16             if(cnt == 8) ans++;
17         }
18     }
19     cout << ans << endl;
20     return 0;
21 }

C - To Infinity

Problem Statement

Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:

  • Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 3334 becomes 44445 becomes 555556 becomes 6666667 becomes 77777778 becomes 88888888 and 9 becomes 9999999991 remains as 1.

For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next. You are interested in what the string looks like after 5×1015 days. What is the K-th character from the left in the string after 5×1015 days?

Constraints

  • S is a string of length between 1 and 100 (inclusive).
  • K is an integer between 1 and 1018 (inclusive).
  • The length of the string after 5×1015 days is at least K.

Input

Input is given from Standard Input in the following format:

S
K

Output

Print the K-th character from the left in Mr. Infinity‘s string after 5×1015 days.


Sample Input 1

Copy

1214
4

Sample Output 1

Copy

2

The string S changes as follows:

  • Now: 1214
  • After one day: 12214444
  • After two days: 1222214444444444444444
  • After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444

The first five characters in the string after 5×1015 days is 12222. As K=4, we should print the fourth character, 2.


Sample Input 2

Copy

3
157

Sample Output 2

Copy

3

The initial string is 3. The string after 5×1015 days consists only of 3.


Sample Input 3

Copy

299792458
9460730472580800

Sample Output 3

Copy

2
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 using namespace std;
 7 const int N = 110;
 8 char s[N];
 9 int main(){
10     ll k, l = 0;
11     cin >> s >> k;
12     ll len = strlen(s);
13     while(l < len && s[l] == ‘1‘) l ++;
14     if(l+1 <= k) printf("%c\n",s[l]);
15     else printf("1\n");
16     return 0;
17 }

D - AtCoder Express 2

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 123, ..., N from west to east. A company called AtCoder Express possesses M trains, and the train i runs from City Li to City Ri (it is possible that Li=Ri). Takahashi the king is interested in the following Q matters:

  • The number of the trains that runs strictly within the section from City pi to City qi, that is, the number of trains j such that piLj and Rjqi.

Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

  • N is an integer between 1 and 500 (inclusive).
  • M is an integer between 1 and 200 000 (inclusive).
  • Q is an integer between 1 and 100 000 (inclusive).
  • 1≤LiRiN (1≤iM)
  • 1≤piqiN (1≤iQ)

Input

Input is given from Standard Input in the following format:

N M Q
L1 R1
L2 R2
:
LM RM
p1 q1
p2 q2
:
pQ qQ

Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City pi to City qi.


Sample Input 1

Copy

2 3 1
1 1
1 2
2 2
1 2

Sample Output 1

Copy

3

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.


Sample Input 2

Copy

10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2

Copy

1
1

The first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1. The second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.


Sample Input 3

Copy

10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Sample Output 3

Copy

7
9
10
6
8
9
6
7
8
10

可以用二维树状数组来做。
 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 #define ll long long
 6 #define lowbit(x) x&(-x)
 7 using namespace std;
 8 const int MAX = 1010;
 9 int c[MAX][MAX];
10 void add(int x,int y,int k){
11     for(int i = x; i < MAX; i += lowbit(i)){
12         for(int j = y; j < MAX; j += lowbit(j)){
13             c[i][j] += k;
14         }
15     }
16 }
17 int query(int x, int y){
18     int sum = 0;
19     for(int i = x; i > 0; i -= lowbit(i)){
20         for(int j = y; j > 0; j -= lowbit(j)){
21             sum += c[i][j];
22         }
23     }
24     return sum;
25 }
26 int main(){
27     int n, m, q, l, r;
28     cin >> n >> m >> q;
29     for(int i = 1; i <= m; i ++) {
30         cin >> l >> r;
31         add(l,r,1);
32     }
33     while(q--) {
34         cin >> l >> r;
35         printf("%d\n",query(r,r)-query(l-1,r)-query(r,l-1)+query(l-1,l-1));
36     }
37     return 0;
38 }

原文地址:https://www.cnblogs.com/xingkongyihao/p/9501575.html

时间: 2024-08-29 00:54:34

AtCoder Beginner Contest 106 ABCD的相关文章

AtCoder Beginner Contest 103 D(贪心)

AtCoder Beginner Contest 103 D 题目大意:n个点,除第n个点外第i与第i+1个点有一条边,给定m个a[i],b[i],求最少去掉几条边能使所有a[i],b[i]不相连. 按右端点从小到大排序,如果当前选的去掉的边在区间内,那么符合条件,否则ans++,并贪心地把去掉的边指向右端点,因为前面的区间都满足条件了,所以要去掉的边要尽量向右移使其满足更多的区间. 1 #include <iostream> 2 #include <cstdio> 3 #incl

AtCoder Beginner Contest 136

AtCoder Beginner Contest 136 Contest Duration : 2019-08-04(Sun) 20:00 ~ 2019-08-04(Sun) 21:40 Website: AtCoder BC-136 后面几题都挺考思考角度D. C - Build Stairs 题目描述: 有n座山从左到右排列,给定每一座山的高度\(Hi\),现在你可以对每座山进行如下操作至多一次:将这座山的高度降低1. 问是否有可能通过对一些山进行如上操作,使得最后从左至右,山的高度呈不下降

AtCoder Beginner Contest 154 题解

人生第一场 AtCoder,纪念一下 话说年后的 AtCoder 比赛怎么这么少啊(大雾 AtCoder Beginner Contest 154 题解 A - Remaining Balls We have A balls with the string S written on each of them and B balls with the string T written on each of them. From these balls, Takahashi chooses one

AtCoder Beginner Contest 155 简要题解

AtCoder Beginner Contest 155 A:签到失败,WA一次. int main() { int a, b, c; cin >> a >> b >> c; if(a == b && b == c) cout << "No"; else if(a == b || a == c || b == c) cout << "Yes"; else cout << &quo

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质)

AtCoder Beginner Contest 152 - F - Tree and Constraints (容斥定理+树上路径的性质) We have a tree with NN vertices numbered 11 to NN. The ii-th edge in this tree connects Vertex aiai and Vertex bibi. Consider painting each of these edges white or black. There ar

【ATcoder】AtCoder Beginner Contest 161 题解

题目链接:AtCoder Beginner Contest 161 原版题解链接:传送门 A - ABC Swap 这题太水,直接模拟即可. 1 #include <iostream> 2 using namespace std; 3 int main() { 4 int a, b, c; 5 cin >> a >> b >> c; 6 swap(a, b); 7 swap(a, c); 8 cout << a << " &

AtCoder Beginner Contest 115 题解

题目链接:https://abc115.contest.atcoder.jp/ A Christmas Eve Eve Eve 题目: Time limit : 2sec / Memory limit : 1024MB Score : 100 points Problem Statement In some other world, today is December D-th. Write a program that prints Christmas if D=25, Christmas E

AtCoder Beginner Contest 121 题解

题目链接:https://atcoder.jp/contests/abc121 A White Cells 分析:题目数据规模很小,直接暴力修改都可以.或者可以推出公式. 代码: 1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 int main() 7 { 8 int a[25][25] = {0}; 9 int H, W, h, w; 10 scanf("%d %d"

AtCoder Beginner Contest 132 F - Small Products

数 sqrt 缩小范围 整除分块 1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <string> 6 #include <algorithm> 7 #include <iostream> 8 using namespace std; 9 #define ll long long 10 1