1
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 5 years have passed since last update.

Atcoder 生活 4日目

Posted at

[前回]
(https://qiita.com/flandrescarlet237/items/8be72ddd34e54fca98cc)

4日目

きょうは、@drkenさんのAtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~で紹介されている第一問から第四問までを解こうとしました。

一問目 ABC086_A

[Product]
(https://atcoder.jp/contests/abc086/tasks/abc086_a)


# include<bits/stdc++.h>
using namespace std;

int main(){
	int a,b;
  	cin >> a >> b;
	if(a*b%2 == 0)cout << "Even" <<endl;
  	else cout << "Odd" <<endl;
}

二問目 ABC081_A

[Placing Marbles]
(https://atcoder.jp/contests/abc081/tasks/abc081_a)

# include<bits/stdc++.h>
using namespace std;

int main(){
	string s;
  	cin >> s;
	int cnt = 0;
   	for(int i = 0;i<3;i++){
  		if(s[i] == '1') ++cnt;
	}
  	cout << cnt << endl;
}

一問目と二問目はやっぱり簡単

三問目 ABC081_B

[Shift only]
(https://atcoder.jp/contests/abc081/tasks/abc081_b)


# include <iostream>
using namespace std;

int N;
int A[210];         

int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> A[i];

    int res = 0;

    while (true) {
        bool exist_odd = false;  
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  
        }

        if (exist_odd) break; 

        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res; 
    }

    cout << res << endl;
}

四問目 : ABC087_B

[Coins]
(https://atcoder.jp/contests/abc087/tasks/abc087_b)

# include<bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int res = 0;
  for (int a = 0; a <= A; ++a) {
    for (int b = 0; b <= B; ++b) {
      for (int c = 0; c <= C; ++c) {
        int total = 500*a + 100*b + 50*c; 
        if (total == X) ++res; 
      }
    }
  }
  cout << res << endl;
}

三問目と、四問目は解けなかったので@drkenさんのものを写しただけですが、whileとboolの使い方をよく理解することができました。四問目はforにこんな使い方があったんだって感じでした。

B問題を自力で解けるように早くなりたいです。

1
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
1
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?