AtCoder Beginner Contest 077(ABC)

本文探讨了两个编程挑战:一是判断一个2x3字符网格在旋转180度后是否保持不变;二是计算在给定不同尺寸的上、中、下三部分的情况下可以构建多少种不同的祭坛。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A - Rotation


Time limit : 2sec / Memory limit : 256MB

Score : 100 points

Problem Statement

You are given a grid with 2 rows and 3 columns of squares. The color of the square at the i-th row and j-th column is represented by the character Cij.

Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

Constraints

  • Ci,j(1≤i≤2,1≤j≤3) is a lowercase English letter.

Input

Input is given from Standard Input in the following format:

C11C12C13
C21C22C23

Output

Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.


Sample Input 1

pot
top

Sample Output 1

YES

This grid remains the same when rotated 180 degrees.


Sample Input 2

tab
bet

Sample Output 2

NO

This grid does not remain the same when rotated 180 degrees.


Sample Input 3

eye
eel

Sample Output 3

NO


 1     #include <iostream>
 2     #include <cstring>
 3     #include <cstdio>
 4     #include <algorithm>
 5      
 6     using namespace std;
 7     string s,s1;
 8     int main(){
 9         cin>>s>>s1;
10         bool prime=true;
11         int slen=s.length();
12         int sslen=s1.length();
13         for(int i=0,j=sslen-1;i<slen&&j>=0;i++,j--){
14             if(s[i]!=s1[j])
15                 {
16                     prime=false;
17                     break;
18                 }
19         }
20         if(prime)
21             cout<<"YES"<<endl;
22         else
23             cout<<"NO"<<endl;
24         return 0;
25     }

 

B - Around Square


Time limit : 2sec / Memory limit : 256MB

Score : 200 points

Problem Statement

Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

Constraints

  • 1≤N≤109
  • N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the largest square number not exceeding N.


Sample Input 1

10

Sample Output 1

9

10 is not square, but 9=3×3 is. Thus, we print 9.


Sample Input 2

81

Sample Output 2

81

Sample Input 3

271828182

Sample Output 3

271821169


 1     #include <iostream>
 2     #include <cmath>
 3     #include <cstring>
 4     #include <cstdio>
 5      
 6     using namespace std;
 7     int n;
 8     int main(){
 9         while(cin>>n){
10             int a=sqrt(n);
11             cout<<a*a<<endl;
12         }
13         return 0;
14     }

 

C - Snuke Festival


Time limit : 2sec / Memory limit : 256MB

Score : 300 points

Problem Statement

The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.

He has N parts for each of the three categories. The size of the i-th upper part is Ai, the size of the i-th middle part is Bi, and the size of the i-th lower part is Ci.

To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.

How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

Constraints

  • 1≤N≤105
  • 1≤Ai≤109(1≤iN)
  • 1≤Bi≤109(1≤iN)
  • 1≤Ci≤109(1≤iN)
  • All input values are integers.

Input

Input is given from Standard Input in the following format:

N
A1  AN
B1  BN
C1  CN

Output

Print the number of different altars that Ringo can build.


Sample Input 1

2
1 5
2 4
3 6

Sample Output 1

3

The following three altars can be built:

  • Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
  • Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
  • Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

Sample Input 2

3
1 1 1
2 2 2
3 3 3

Sample Output 2

27

Sample Input 3

6
3 14 159 2 6 53
58 9 79 323 84 6
2643 383 2 79 50 288

Sample Output 3

87


 1     #include <iostream>
 2     #include <cstring>
 3     #include <cstdio>
 4     #include <algorithm>
 5     #include <vector>
 6     #define ll long long int
 7     #define N 100005
 8     using namespace std;
 9     vector<int> k[3];
10     ll dp[3][N];
11     int main(){
12         int n;
13         cin>>n;
14         for(int i=0;i<3;i++){
15             for(int j=0;j<n;j++){
16                 int x;
17                 cin>>x;
18                 k[i].push_back(x);
19             }
20             sort(k[i].begin(),k[i].end());
21         }
22         dp[0][0]=1;
23         for(int i=1;i<n;i++)
24             dp[0][i]=dp[0][i-1]+1;
25      
26         for(int i=1;i<3;i++){
27             for(int j=0;j<n;j++){
28                 int x=lower_bound(k[i-1].begin(),k[i-1].end(),k[i][j])-k[i-1].begin();
29                 dp[i][j]+=dp[i-1][x-1];
30             }
31             for(int t=1;t<n;t++)
32                 dp[i][t]+=dp[i][t-1];
33         }
34         cout<<dp[2][n-1]<<endl;
35         return 0;
36     }

 

转载于:https://www.cnblogs.com/zllwxm123/p/7799320.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值