夢追い人

"It takes a dreamer to make a dream come true."―Vincent Willem van Gogh

題名はネタ切れ。認めます。

1050

意外と単純なdpだったよ。オーダー見積もりを鍛えなきゃとか思った。

#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;
int main()
{
    int N;
    scanf("%d",&N);
    int map[N][N];
    for (int i=0; i<N; i++)
		for (int j=0; j<N; j++)
			scanf("%d",&map[i][j]);
	int dp[N][N][N];
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			int sum = 0;
			for (int k=j; k<N; k++) {
				sum += map[i][k];
				dp[i][j][k] = sum;
			}
		}
	}
	int res = INT_MIN;
	for (int k=0; k<N; k++) {
		for (int l=k; l<N; l++) {
			for (int i=0; i<N; i++) {
				int sum = 0;
				for (int j=i; j<N; j++) {
					sum += dp[j][k][l];
					res = max(res, sum);
				}
			}
		}
	}
	printf("%d\n", res);
}

1017

こんなめんどくさい問題!!!コピペですが何か?(;・∀・)

#include <iostream>

using namespace std;

int main()
{
    while ( true )
    {
        int p[7];
        for ( int i=1; i<=6; i++ )
            cin >> p[i];

        int num = 0;
        int s1 = 0;
        int s2 = 0;

        //  6
        num += p[6];
        //  5
        num += p[5];
        s1 += p[5] * 11;
        //  4
        num += p[4];
        s2 += p[4] * 5;
        //  3
        num += ( p[3] + 3 ) / 4;
        switch ( p[3] % 4 )
        {
            case 0:  s1 += 0, s2 += 0;  break;
            case 1:  s1 += 7, s2 += 5;  break;
            case 2:  s1 += 6, s2 += 3;  break;
            case 3:  s1 += 5, s2 += 1;  break;
        }
        //  2
        if ( s2 < p[2] )
            p[2] -= s2;
        else
            s1 += ( s2 - p[2] ) * 4,
            p[2] = 0;
        num += ( p[2] + 8 ) / 9;
        s1 += ( 9 - p[2]%9 ) % 9 * 4;
        //  1
        p[1] -= min( s1, p[1] );
        num += ( p[1] + 35 ) / 36;

        if ( num == 0 )
            break;

        cout << num << endl;
    }

    return 0;
}

1519

ただのdfs

#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;
string dfs(string str) {
	int res = 0;
	if (str.length() == 1) return str;
	for (int i=0; i<str.length(); i++) {
		res += str[i] - '0';
	}
	stringstream ss;
	ss << res;
	return dfs(ss.str());
}
int main() {
	string num;
	while (cin>>num) {
		if (num == "0") break;
		cout << dfs(num) << endl;
	}
}

1555

定数の扱いがネック

#include <cstdio>
#include <iostream>
#include <sstream>
using namespace std;

int main() 
{
    int n[9];
    while (scanf("%d", &n[0])!=EOF) {
        for (int i=1; i<9; i++) scanf("%d", &n[i]);
        bool first = true;
        string res = "";
        for (int i=0; i<8; i++) {
            if (n[i] == 0) continue;
            stringstream ss1;
            ss1 << 8-i;
            string xstr;
            if (i == 7) {
                xstr = "x";
            } else {
                xstr = "x^" + ss1.str();
            }
            if (first) {
                first = false;
                if (n[i] == -1) {
                    res += "-" + xstr;
                } 
                else if (n[i] == 1) {
                    res += xstr;
                } 
                else {
                    stringstream ss;
                    ss << n[i];
                    res += ss.str() + xstr;
                }
            }
            else {
                if (n[i] == -1) {
                    res += " - " + xstr;
                }
                else if (n[i] == 1) {
                    res += " + " + xstr;
                }
                else if (n[i] < 0) {
                    res += " - ";
                    stringstream ss;
                    ss << -n[i];
                    res += ss.str() + xstr;
                }
                else {
                    res += " + ";
                    stringstream ss;
                    ss << n[i];
                    res += ss.str() + xstr;
                }
            }
        }
		if (first) {
			stringstream ss;
			ss << n[8];
			res += ss.str();
		} else {
			if (n[8] < 0) {
				stringstream ss;
				ss << -n[8];
				res += " - " + ss.str();
			}
			else if (n[8] > 0) {
				stringstream ss;
				ss << n[8];
				res += " + " + ss.str();
			}
		}
        cout << res << endl;
    }
}

1562

ただのdfs

#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int n, m;
vector<string> map(100);
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

void dfs(int x, int y) {
	map[x][y] = '*';
	for (int i=0; i<8; i++) {
		int nx = x + dx[i], ny = y + dy[i];
		if (nx>=0 && nx<n && ny>=0 && ny<m && map[nx][ny]=='@') {
			dfs(nx, ny);
		}
	}
	return;
}

int main() {
	while (scanf("%d%d", &n, &m)) {
		if (n == 0 && m == 0) break;
		for (int i=0; i<n; i++) {
			cin >> map[i];
		}
		int res = 0;
		for (int i=0; i<n; i++) for (int j=0; j<m; j++) {
			if (map[i][j] == '@') {
				dfs(i, j);
				res++;
			}
		}
		printf("%d\n", res);
	}
}

2533

LIS。ただの

#include <cstdio>
#include <climits>
#include <algorithm>
using namespace std;

int main() {
	int n; scanf("%d", &n);
	int a[n];
	for (int i=0; i<n; i++)
		scanf("%d", &a[i]);
	int dp[n];
	fill(dp,dp+n,INT_MAX);
	for (int i=0; i<n; i++)
		*lower_bound(dp,dp+n,a[i])=a[i];
	printf("%d\n",lower_bound(dp,dp+n,INT_MAX)-dp);
}

あ、そうそう。100問達成したよ♪

広告を非表示にする