2
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 生活 6日目

Posted at

[前回]
(https://qiita.com/flandrescarlet237/items/07e4292b09991cd1be67)

6日目

今回も前回と同じように@drkenさんのAtCoder に登録したら次にやること ~ これだけ解けば十分闘える!過去問精選 10 問 ~の第8問から第10問まで解きました。

第8問 ABC085_C

[Otoshidama]
(https://atcoder.jp/contests/abc085/tasks/abc085_c)


# include <bits/stdc++.h>
using namespace std;
int main(){
	int N,Y;
  	cin >> N >> Y;
	int residue = 0;
  	int res10000 = -1,res5000 = -1,res1000 = -1  ;
  	for(int x = 0;x <= N;x++){
    	for(int y = 0;y <= N-x;y++){
          	int z = N-x-y;
          	int total = 10000*x +5000*y +1000*z;
            if(total == Y){
            res10000 = x;
            res5000 = y;
            res1000 = z;
            }
        }	
    }
  	cout << res10000 << " " << res5000 <<  " " << res1000 << endl;    
}

解けなかったが、理解はしやすかった。

第9問 ABC049_C

[白昼夢]
(https://atcoder.jp/contests/abc049/tasks/arc065_a)


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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {
    string S;
    cin >> S;

    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for (int i = 0; i < S.size();) {
        bool can2 = false; 
        for (int j = 0; j < 4; ++j) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }
        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
}

substr関数の使い方とbool型をよく知れました。

第10問 ABC086_C

[Traveling]
(https://atcoder.jp/contests/abc086/tasks/arc089_a)


# include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

解説を見ればなんとかなるけど、C問題となるとまず最初に何をらればいいかすらわからなくなりました。

とりあえず10問とき終わったので、次からはほかのB問題を解いていこうと思います。

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