0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AtCoder Beginner Contest 174

Posted at

A - Air Conditioner

C++
# include<iostream>
# include<vector>
# include<algorithm>
# include<iomanip>
# include<utility>
# include<iomanip>
# include<map>
# include<queue>
# include<cmath>
# include<cstdio>
 
# define rep(i,n) for(int i=0; i<(n); ++i)
# define pai 3.1415926535897932384
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
int main(int argc, const char * argv[]) {
    
    int X;
    cin >> X;
    
    if(X>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

B - Distance

  • 少数で何かあるといけないからPythonを使用
Python
import math
 
N, D = list(map(int, input().split()))
 
c=0
for i in range(0, N):
    X, Y = list(map(int, input().split()))
    if math.sqrt(X * X + Y * Y) <= D:
        c+=1
    
print(c)

C - Repsept

  • 計算途中で余りを求めても同じ結果を返す法則があります
C++
# include<iostream>
# include<vector>
# include<algorithm>
# include<iomanip>
# include<utility>
# include<iomanip>
# include<map>
# include<queue>
# include<cmath>
# include<cstdio>
 
# define rep(i,n) for(int i=0; i<(n); ++i)
# define pai 3.1415926535897932384
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
int K;
 
int main(int argc, const char * argv[]) {
    
    cin >> K;
    
    ll c=0;
    ll num=7;
    while(c<=K){
        c++;
        if(num%K==0){
            break;
        }
        num = num%K;
        num = (num * 10 + 7);
    }
    
    if(num%K==0) cout << c << endl;
    else cout << "-1" << endl;
    
    return 0;
}

D - Alter Altar

  • 最後の要素からswapするだけです
C++
# include<iostream>
# include<vector>
# include<algorithm>
# include<iomanip>
# include<utility>
# include<iomanip>
# include<map>
# include<queue>
# include<cmath>
# include<cstdio>
 
# define rep(i,n) for(int i=0; i<(n); ++i)
# define pai 3.1415926535897932384
 
using namespace std;
using ll =long long;
using P = pair<int,int>;
 
char c[200000];
 
int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    cin >> c;
    
    int w=0;
    int count=0;
    for(int i=N-1; i>0; i--){
        if(c[i] == 'R'){
            while(w<N&&i>w){
                if(c[w]=='W'){
                    c[w] = c[i];
                    c[i] = 'W';
                    count++;
                    break;
                }
                w++;
            }
        }
    }
    
    cout << count << endl;
    
    return 0;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?