7.18总结

· · 个人记录

声明

代码仅供参考,请勿抄袭!

题目信息

题目名称 难度 思路(没有/有一点/有) 分数
T807797 T3 普及− 有一点 -
T807800 T6 普及− 有一点 -
T807801 T7 普及− 没有 -

题目详细

T3

#include <iostream>
#define int unsigned long long
#define endl '\n'
using namespace std;
struct st{
    int x, y;//x坐标,y坐标
}a[1005][1005];
signed main(){
    int n, m, x1, y1;
    cin >> m >> n >> x1 >> y1;//要先输入m再输入n,因为输入顺序为m, n, sx, sy
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= m; j++){
            cin >> a[i][j].x >> a[i][j].y;//输入
        }
    }

    while (true){
        cout << x1 << " " << y1 << endl;//输出不为0 0的坐标
        int x2 = x1;//定义x2,用来临时存x1
        int y2 = y1;//定义y2,用来临时存y1
        x1 = a[x2][y2].x;//将x1变成a[x2][y2].x,更新
        y1 = a[x2][y2].y;//将y1变成a[x2][y2].y,更新
        if (x1 == 0 && y1 == 0){//如果旅行结束,
            return 0;//则直接结束程序
        }
    }
    return 0;
}
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
struct st{
    double m, v, d;//重量,价值,单价
}a[100005];
int cmp(st a1, st a2){
    return a1.d > a2.d;//单价排序
}
signed main(){
    int n, t;
    cin >> n >> t;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i].m >> a[i].v;
        a[i].d = a[i].v / a[i].m;//单价为:a[i].价值 / a[i].重量(KG)
    }
    double cnt = 0;
    sort(a+1, a+n+1, cmp);//排序
    for (int i = 1; i <= n; i++){
        if (t - a[i].m >= 0){//如果足够拿这个
            cnt += a[i].v;//那么带上它
            t -= a[i].m;
        }
        else{
            cnt += a[i].d * t;//否则加上单价*可以买的个数(t)
            break;
        }
    }
    printf("%.2lf", cnt);//保留两位小数
    return 0;
}

T4

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
struct st{
    int sj;//数据
    int bh;//编号
}a[100005];
int cmp(st a1, st a2){
    if (a1.sj == a2.sj){//如果耗费时间一致
        return a1.bh < a2.bh;//那么按编号排序
    }
    else{
        return a1.sj < a2.sj;//否则直接按时间排序。
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> a[i].sj;//输入a[i].sj
        a[i].bh = i;//a[i].编号 = i。
    }
    sort(a+1, a+n+1, cmp);//排序
    double sum=0;//最终答案
    for(int i = 1; i <= n; i++){
        cout << a[i].bh << " ";//输出编号
        for(int j = 1; j <= n - i; j++){
            sum += a[j].sj;//sum加上a[i]的数据
        }
    }
    cout << endl;
    cout << fixed << setprecision(2) << sum / n;//输出均值
    return 0;
}