洛谷入门算法题

p1047校门外的树

#include<iostream>
using namespace std;
const int N = 1e4 + 10;
bool L[N];
int l, m;
int main()
{
	cin >> l >> m;
	while (m--)
	{
		int u, v;
		cin >> u>>v;
		for (int i = u; i <= v; i++)
			L[i] = true;
	}
	cout << std::count(&L[0],&L[l+1],false);
}

p5731蛇形方阵

#include<iostream>
using namespace std;
int a[10][10];
int main()
{
	int n; cin >> n;
	int l = n, w = n;
	if (n % 2)a[n / 2 + 1][ n / 2 + 1] = n * n;
	for (int i=1,j=1, t=1; t <= n * n;i++,j++)
	{
		while (j < l)a[i][j++] = t++;if(l) l--;
		while (i < w)a[i++][j] = t++;if(w) w--;
		while (j > n-l)a[i][j--] = t++;
		while (i > n-w)a[i--][j] = t++;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			printf("%3d", a[i][j]);
		printf("\n");
	}
}

p1789插火把

#include<iostream>
using namespace std;
int a[105][105], n, m, k, x, y, cnt;
int main() {
    cin >> n >> m >> k;
    while(m--) 
    {
        cin >> x >> y;
        for (int i = x + 1; i <= x + 3; i++)
            for (int j = y + 1; j <= y + 3; j++)
                a[i][j] = 1;
        a[x][y + 2] = 1;
        a[x + 4][y + 2] = 1;
        a[x + 2][y + 4] = 1;
        a[x + 2][y] = 1; 
    }
    while(k--) 
    {
        cin >> x >> y;
        for (int i = x ; i <= x + 4; i++)
            for (int j = y ; j <= y + 4; j++)
                a[i][j] = 1;
    }
    for (int i = 3; i <= n+2; i++)
        for (int j = 3; j <= n+2; j++)
            if (a[i][j] == 0)cnt++;
    std::cout << cnt; 
}

p1125笨小猴

#include<bits/stdc++.h>
using namespace std;
bool judge(int n) {
	if (n <= 1)	return 0;
	for (int i = 2; i <= sqrt(n); ++i)
		if (!(n % i))	return 0;
	return 1;
}
int main()
{
	int maxn = 0, minn = 101;
	string s; cin >> s;
	for (char i = 'a'; i <= 'z'; i++)
	{
		int n=std::count(s.begin(), s.end(), i);
		if (n > maxn)maxn = n;
		if (n < minn&&n)minn = n;
	}
	if (judge(maxn - minn))cout << "Lucky Word" << endl<<maxn-minn;
	else cout << "No Answer" << endl<<0;
}

p1603斯诺登的密码

#include<bits/stdc++.h>
using namespace std;
map<string, int>m;
int score[100],a;
string s;
int main() {

    m["one"] = 1; m["two"] = 2; m["three"] = 3; m["four"] = 4; m["five"] = 5; m["six"] = 6; m["seven"] = 7; m["eight"] = 8; m["nine"] = 9; m["ten"] = 10;
        m["eleven"] = 11; m["twelve"] = 12; m["thirteen"] = 13; m["fourteen"] = 14; m["fifteen"] = 15; m["sixteen"] = 16; m["seventeen"] = 17; m["eighteen"] = 18; m["nineteen"] = 19; m["twenty"] = 20;
    m["a"] = 1; m["both"] = 2; m["another"] = 1; m["firscore"] = 1; m["second"] = 2; m["third"] = 3;
    for (int i = 1; i <= 6; i++) {
        cin >> s;
        if (m[s]) {
            int k = m[s] * m[s] % 100;
            if (k == 0)continue;
            score[++a] = k;
        }
    }
    sort(score+1, score + a+1);
    cout << score[1];
    for (int i = 2; i <= a; i++) {
        if (score[i] < 10)cout << 0;
        cout << score[i];
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值