2017 Multi-University Training Contest - Team 7

本文分享了作者在算法竞赛中遇到的极角排序问题的学习经历,并提供了具体的代码实现,包括如何计算点的角度并进行排序,以及如何通过极角排序解决特定问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这场打的很烂、

极角排序都不知道

1005

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b)    memset(a, b, sizeof a)
#define REP(i, x, n)    for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 2e5 + 10;
const int INF = 1e9 + 10;

int main(){
    int t;    scanf("%d", &t);
    while(t--) {
        int n;    scanf("%d", &n);
        printf("%d\n", (n + 1) / 2 + 1);
    }
    return 0;
}



1008

这几天打百度之星现在才把这题补掉、期间做了一些关于极角排序的题目

总算理解了(都怪我高中太狂妄,要定了选做题的几何,就没关极坐标的那个选修)

#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const LL MOD = 1e9 + 7;
const int qq = 5e4 + 10;
const int INF = 1e9 + 10;
const double eps = 1e-8;
struct Point {
	int x, y;
	double angle;
	LL val;
	Point(){}
	Point(int _x, int _y, LL _val) : x(_x), y(_y), val(_val){}
	bool operator < (const Point &w) const {
		return angle < w.angle;
	}
}p[qq];

int main(){
	printf("%lf\n", atan(-	1. / 0.));
	int t;	scanf("%d", &t);
	while(t--) {
		int n;	scanf("%d", &n);
		for(int i = 0; i < n; ++i) {
			int x, y;	LL val;
			scanf("%d%d%lld", &x, &y, &val);
			p[i] = Point(x, y, val);
			p[i].angle = atan(y * 1.0 / x);
		}
		sort(p, p + n);
		/*for(int i = 0; i < n; ++i) {
			printf("%lf %lf\n", p[i].x, p[i].y);
		}*/
		LL sumL, sumR;
		sumL = sumR = 0;
		for(int i = 0; i < n; ++i) {
			if(p[i].x > 0)	sumR += p[i].val;
			else	sumL += p[i].val;
		}
		LL maxn = sumL * sumR;
		for(int i = 0; i < n; ++i) {
			if(p[i].x > 0) {
				sumL += p[i].val;
				sumR -= p[i].val;
			} else {
				sumL -= p[i].val;
				sumR += p[i].val;
			}
			maxn = max(maxn, sumL * sumR);
		}
		printf("%lld\n", maxn);
	}
	return 0;
}




1011

队友打表过得

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = 1e7 + 10;
const int MOD = 1e9 + 7;
int a[N];
void init() {
    a[1]=1;
    a[2]=2;
    a[3]=2;
    int top=4;
    for(int i=3;i<N;i++) {
        if(a[top-1]==1) a[top]=2;
        else a[top]=1;
        if(a[i]==2) {
            top++;
            a[top]=a[top-1];
        }
        top++;
        if(top>N) break;
    }
}
int main() {
    init();
    int t,n;
    scanf("%d",&t);
    while(t--) {
        scanf("%d",&n);
        printf("%d\n",a[n]);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值