小猴编程c++z3下第6讲阶段诊断答案

1.机械加工

 #include <iostream>
 #include <algorithm>
 using namespace std;
 struct node
 {
    int d, w, p;
 }a[200010];
 int T, n, m, k;
 bool cmp(node x, node y)
 {
    return x.p < y.p;
 }
 int main()
 {
    cin >> T >> m >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].d >> a[i].w >> a[i].p;
        if (k) a[i].p += T - a[i].d;
    }
    sort(a + 1, a + n + 1, cmp);
    long long ans = 0;
    for (int i = 1; i <= n; i++)
    {
        if (m > a[i].w)
        {
            ans += 1ll * a[i].p * a[i].w;
                        m -= a[i].w;
        }
        else
        {
            ans += m * a[i].p;
            break;
        }
    }
    cout << ans << endl;
    return 0;
 }

2.猫咪照相

 #include <iostream>
 #include <algorithm>
 using namespace std;
 int n, k, a[110], b[110], w[20], ans;
 bool check()
 {
    for (int r = 2; r <= n; r++)
    {
        int x = w[r], y = w[r - 1];
        for (int i = 1; i <= k; i++)
            if (a[i] == x && b[i] == y || b[i] == x && a[i] == y)
                return false;
    }
    return true;
 }
 int main()
 {
    cin >> n >> k;
    for (int i = 1; i <= k; i++)
    {
    	cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++)
    {
    	w[i] = i;
    }
    do
    {        
    	if (check())
    	{
    		ans++;
    	}
    }while (next_permutation(w + 1, w + n + 1));
    cout << ans << endl;
    return 0;
 }

3.愚公移山

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

int n, ans;

void dfs(int x, int last, int sum)
{
    if (sum==n) 
    {
        if (x-1<2)
        {
        	return;
        	}
        ans++;
        return;
    }
    for (int i=last+1; i<=n-sum; i++) 
    {
        dfs(x+1, i, sum+i);
    }
}

int main()
{
    cin >> n;
    dfs(1, 0, 0);
    cout << ans << endl;
    return 0;
}

4.爱探险的小明

 #include <iostream>
 #include <algorithm>
 using namespace std;
 
 int n;
 string s, t[100010];
 bool cmp(string x, string y)
 {
    return x + y > y + x;
 }
 int main()
 {
    cin >> s;
    s = "a" + s + "a";
    for (int i = 1; i < s.size(); i++)
        if (isdigit(s[i])) 
        {
            if (islower(s[i - 1])) n++;
            t[n] += s[i];
        }
    sort(t + 1, t + n + 1, cmp);
    for (int i = 1; i <= n; i++) cout << t[i];
    cout << endl;
    return 0;
 }

5.递增三元组

 #include <iostream>
 #include <algorithm>
 using namespace std;
 
 int n, a[100010], b[100010], c[100010];
 
 int main()
 {
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
    	cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
    {
    	cin >> b[i];
    }
    for (int i = 1; i <= n; i++)
    {
    	cin >> c[i];
    }
    sort(a + 1, a + n + 1);
    sort(c + 1, c + n + 1);
    long long ans = 0;
	for (int i = 1; i <= n; i++)
	{
		int x = upper_bound(a + 1, a + n + 1, b[i]) - a;
		int y = lower_bound(c + 1, c + n + 1, b[i]) - c;
		ans += 1ll * (x - 1) * (n - y + 1);
	}
 cout << ans << endl;
 return 0;
 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值