标签:src follow efi horizon find lse lines led amp
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.
It can be proved that the positions of the roads do not affect the area.
Input is given from Standard Input in the following format:
A B
Print the area of this yard excluding the roads (in square yards).
2 2
1
In this case, the area is 1 square yard.
5 7
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 }
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)?
Input is given from Standard Input in the following format:
N
Print the count.
105
1
Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.
7
0
1 has one divisor. 3, 5 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 }
Mr. Infinity has a string S consisting of digits from 1
to 9
. Each time the date changes, this string changes as follows:
2
in S is replaced with 22
. Similarly, each 3
becomes 333
, 4
becomes 4444
, 5
becomes 55555
, 6
becomes 666666
, 7
becomes 7777777
, 8
becomes 88888888
and 9
becomes 999999999
. 1
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?
Input is given from Standard Input in the following format:
S K
Print the K-th character from the left in Mr. Infinity‘s string after 5×1015 days.
1214 4
2
The string S changes as follows:
1214
12214444
1222214444444444444444
12222222214444444444444444444444444444444444444444444444444444444444444444
The first five characters in the string after 5×1015 days is 12222
. As K=4, we should print the fourth character, 2
.
3 157
3
The initial string is 3
. The string after 5×1015 days consists only of 3
.
299792458 9460730472580800
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 }
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., 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:
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.
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
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.
2 3 1 1 1 1 2 2 2 1 2
3
As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.
10 3 2 1 5 2 8 7 10 1 7 3 10
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.
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
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 }
AtCoder Beginner Contest 106 ABCD
标签:src follow efi horizon find lse lines led amp
原文地址:https://www.cnblogs.com/xingkongyihao/p/9501575.html