Atcoder 209

Atcoder记录

有关于排列的计算

链接:ABC209D
题意:给定一组长度为n的数组,对于数组上的每个数字,你可以选择小于等于该数字的任意一个数字,从而构成新的数组,新数组要求没有重复元素,求有多少种排列方式?
思路:首先这是一道关于排列的题目,对于原序列上的每个数,数的大小就代表可以选择的元素个数,根据排列的计算公式n(n-1)(n-2)..*1,这是对于每个位置上都有n种可能的结果,对于这题,我们需要先进行排序,因为较大的数字,其多出来的元素无法被较小的数字进行选取,而较小的数字是可以被较大数字选取,所以要先对较小的情况进行处理然后再处理较大的情况,再根据公式求解.
这样对于每一位,都减去前面已经选过的可能,再将每一位的可能的数量相乘即结果。
代码:

const int N = 2e5+100;
ll a[N];
int main() {
	IOS;cin.tie(0),cout.tie(0);//NO scanf/printf!
	int n; read(n);
	for(int i = 0; i < n;i++){
		read(a[i]);
	}
	sort(a, a+n);
	ll ans = 1, num = 0;
	for(int i = 0; i < n;i++){
		ans *= (a[i]-num++);
		ans %= mod1;
	}
	cout << ans << endl;
	return 0 ;
}

map相关函数(还需学习积累)

链接:ABC213D
思路:认真分析题意可知,如果两张牌x之间及y之间都是空白牌,在操作完之后那么他们一定对角或相邻,显然对于x和y是互不影响的,我们可以对其分别排序,再将它们分别按顺序赋值成1、2。。。n,最后按照原顺序分别输出每张牌。

int h, w, c;//我的代码,比较拉跨-_-
struct node{
	int first, second;
	int index;
}pr[N], ans[N];
unordered_map<int, int>mp;
bool cmp1(struct node a, struct node b){
	return a.first < b.first;
}
bool cmp2(struct node a, struct node b){
	return a.second < b.second;
}
bool cmp3(struct node a, struct node b){
	return a.index < b.index;
}
int main() {
	IOS;cin.tie(0),cout.tie(0);//NO scanf/printf!
	read(h), read(w), read(c);
	for(int i = 0; i < c;i++){
		read(pr[i].first); read(pr[i].second);
		pr[i].index = i;
	}
	sort(pr, pr+c, cmp1);
	int d1 = 1;
	for(int i = 0; i < c;i++)
	{
		if(mp[pr[i].first] == 0) mp[pr[i].first] = d1++;
		else  continue;
	}
	sort(pr, pr+c, cmp3);
	for(int i = 0; i < c;i++){
		ans[i].first = mp[pr[i].first];
	}
	mp.clear();
	sort(pr, pr+c, cmp2);
	int d2 = 1;
	for(int i = 0; i < c;i++){
		if(mp[pr[i].second] == 0) mp[pr[i].second] = d2++;
		else  continue;
	}	
	sort(pr, pr+c, cmp3);
	for(int i = 0; i < c;i++){
		ans[i].second = mp[pr[i].second];
	}
	for(int i = 0; i < c;i++){
		cout << ans[i].first << ' ' << ans[i].second << '\n';
	}
	return 0 ;
}
 //analyze problems calmly and get solution;
#include <bits/stdc++.h>//大佬的代码
 
using i64 = long long;
 
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int H, W, N;
    std::cin >> H >> W >> N;
    
    std::vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) {
        std::cin >> A[i] >> B[i];
    }
    
    std::vector<int> rows = A, cols = B;
    std::sort(rows.begin(), rows.end());
    rows.erase(std::unique(rows.begin(), rows.end()), rows.end());
    std::sort(cols.begin(), cols.end());
    cols.erase(std::unique(cols.begin(), cols.end()), cols.end());
    
    for (int i = 0; i < N; i++) {
        A[i] = std::lower_bound(rows.begin(), rows.end(), A[i]) - rows.begin() + 1;
        B[i] = std::lower_bound(cols.begin(), cols.end(), B[i]) - cols.begin() + 1;
        
        std::cout << A[i] << " " << B[i] << "\n";
    }
    
    return 0;
}

欧拉路径

链接:ABC213D
题意:
思路:

posted @ 2021-08-12 10:32  倩影一梦  阅读(92)  评论(0)    收藏  举报