AtCoder Beginner Contest 077

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

Copy
pot
top

Sample Output 1

Copy
YES

This grid remains the same when rotated 180 degrees.


Sample Input 2

Copy
tab
bet

Sample Output 2

Copy
NO

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


Sample Input 3

Copy
eye
eel

Sample Output 3

Copy
NO

 

#include<bits/stdc++.h>
 
#define _ cin.tie(0);ios::sync_with_stdio(false);
using namespace std;
 
int main(){ _
 
 
 
    string str, tmp;
    while(cin >> str >> tmp){
    reverse(str.begin(), str.end());
    if(str == tmp) cout << "YES" << endl;
    else cout << "NO" << endl;
    }
}

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

Copy
10

Sample Output 1

Copy
9

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


Sample Input 2

Copy
81

Sample Output 2

Copy
81

Sample Input 3

Copy
271828182

Sample Output 3

Copy
271821169
#include<bits/stdc++.h>
 
#define _ cin.tie(0);ios::sync_with_stdio(false);
using namespace std;
using LL = long long;
int main(){ _
    LL n, m;
    while(cin >> n){
        for(LL i = 1; i*i <= n; i++) m = i * i;
        cout << m << endl;

/*
int i = sqrt(n);
cout << i * i << endl;
*/
    }      
}

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

Copy
2
1 5
2 4
3 6

Sample Output 1

Copy
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

Copy
3
1 1 1
2 2 2
3 3 3

Sample Output 2

Copy
27

Sample Input 3

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

Sample Output 3

Copy
87
#include<bits/stdc++.h>

#define _ cin.tie(0);ios::sync_with_stdio(false);
using namespace std;

#define rep(n) for(int i = 0; i < n; i++)
#define Sort(a) sort(a.begin(), a.end())
using LL = long long;
const int N = 100000 + 5;

LL tree[N];
LL Query(int pos){
    LL sum = 0;
    while(pos > 0){
        sum += tree[pos];
        pos -= (pos & -pos);
    }
    return sum;
}

void Add(int pos,LL num){
    while(pos <= N){
        tree[pos] += num;
        pos += (pos & -pos);
    }
}
vector<LL> a, b, c;
int main(){ _
    LL  n, m;
    memset(tree, 0, sizeof(tree));
    cin >> n;
    rep(n) { cin >> m; a.push_back(m); }
    rep(n) { cin >> m; b.push_back(m); }
    rep(n) { cin >> m; c.push_back(m); }
    Sort(a), Sort(b), Sort(c);

    for(int i = 0; i < n; i++){
        auto tmp = lower_bound(a.begin(), a.end(), b[i]);
        int num = tmp - a.begin();
        Add(i + 1, num);

    }
    LL sum = 0;
    for(auto &i : c){
        auto tmp = lower_bound(b.begin(), b.end(), i);
        int cur = tmp - b.begin();
        LL num = Query(cur);
        sum += num;
    }
    /**
    LL sum = 0;
    rep(n){
        LL A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        LL B = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
        sum += (A * B);
    }*/
    cout << sum << endl;
}

 

  

转载于:https://www.cnblogs.com/Pretty9/p/7784838.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值