1.回看7.18-7.20总结

map和pair-

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

const int maxn = 10;
vector<pair<int, int>> q[maxn];

int main() {
    // 向 q[0] 中添加一个 pair
    q[0].push_back(make_pair(1, 2));

    // 访问 q[0] 中的第一个 pair
    cout << "First pair: (" << q[0][0].first << ", " << q[0][0].second << ")" << endl;

    // 修改 pair 的值
    q[0][0].first = 3;
    q[0][0].second = 4;

    cout << "Modified pair: (" << q[0][0].first << ", " << q[0][0].second << ")" << endl;

    return 0;
}

map

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

const int maxn = 10;
vector<map<int, int>> q[maxn];

int main() {
    // 向 q[0] 中添加一个 map
    map<int, int> m;
    m[1] = 2;
    m[3] = 4;
    q[0].push_back(m);

    // 访问 q[0] 中的第一个 map
    cout << "First map:" << endl;
    for (auto& p : q[0][0]) {
        cout << p.first << " -> " << p.second << endl;
    }

    // 修改 map 中的值
    q[0][0][1] = 5;

    cout << "Modified map:" << endl;
    for (auto& p : q[0][0]) {
        cout << p.first << " -> " << p.second << endl;
    }

    return 0;
}

image

用于图

#include <vector>
using namespace std;

const int maxn = 10;
vector<pair<int, int>> adj[maxn];  // 图的邻接表,存储节点的边和权重
adj[u].push_back(make_pair(v, weight));  // 添加从 u 到 v 的边,权重为 weight


#include <vector>
#include <map>
using namespace std;

const int maxn = 10;
vector<map<int, int>> adj[maxn];  // 图的邻接表,存储节点的边和权重
adj[u][v] = weight;  // 添加从 u 到 v 的边,权重为 weight

image

vj2

还是不懂飞机和约数

二分复习

跳石头

突破点在于思路:不受m限制,你要枚举最短距离,看这个最短距离能否在只移动m块时实现。

跳石头

下午团队赛

团队赛

直线交点

(看不懂)
image

#include<bits/stdc++.h>
using namespace std;
##define int long long
const int maxn=3e6+10;
typedef pair<int,int> pii;
int n,m;
long long cnt;
map<pii,int> mp1;
map<pair<pii,int>,int> mp2;
void solve()
{
	cin>>n;
	cnt=0;
	mp1.clear();
	mp2.clear();
	for(int i=1; i<=n; i++)
	{
		int a,b,c,d;
		int x=c-a;
		int y=b-d;
		int z=a*d-b*c;
		int k=__gcd(x,y);
		if(k!=0)
		{
			x/=k;
			y/=k;
			z/=k;
		}
		mp1[ {x,y}]++;
		mp2[ {x,y},z]++;
		cnt+=(i-1+mp2[ {x,y},z]-mp1[ {x,y}]);
	}
	cout<<cnt<<endl;
}

(易理解
image

中位数

image

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;

const int N = 1e5 + 10;
struct node {
    ll a, b, c, d;
} st[N];

ll dx[N], dy[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<ll> dx, dy;
        for(int i = 0; i < n; i++) {
            cin >> st[i].a >> st[i].b >> st[i].c >> st[i].d;
            dx.push_back(st[i].a); dx.push_back(st[i].c);
            dy.push_back(st[i].b); dy.push_back(st[i].d);
        }
        sort(dx.begin(), dx.end());
        sort(dy.begin(), dy.end());
        
        ll sum = 0, x = dx[n - 1], y = dy[n - 1];
        for(int i = 0; i < n; i++) {
            ll a = st[i].a, b = st[i].b, c = st[i].c, d = st[i].d;
            if(x > c || x < a) {
                sum += min(abs(x - a), abs(x - c));
            }
            if(y > d || y < b) {
                sum += min(abs(y - b), abs(y - d));
            }
        }
        cout << sum << "\n";
    }
    return 0;
}

vj1 概率最大问题

image

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	double n,m,k;
	cin>>n>>m>>k;
	double ans;
	double t=k-1;
	if(m>=k)
	ans=t/k+((m-t)/(n+m-t))/k;
	else
	ans=m/k;
	cout<<fixed<<setprecision(9)<<ans<<endl;
}
posted on 2024-07-23 08:34  Hoshino1  阅读(1)  评论(0编辑  收藏  举报