2021 ICPC 网络赛2

Posted 行码棋

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了2021 ICPC 网络赛2相关的知识,希望对你有一定的参考价值。

A

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e3 + 7;

int a[N], b[N], id[N];
int n, m, tot;
vector<int> G[N], ans;

int c[N];
int lowbit(int x) {
    return x & -x;
}

void add(int x, int v) {
    while (x <= n) {
        c[x] += v;
        x += lowbit(x);
    }
}

int ask(int x) {
    int res = 0;
    while (x > 0) {
        res += c[x];
        x -= lowbit(x);
    }
    return res;
}

bool check() {
    for (int i = 2; i <= n; ++i) {
        if (a[i] < a[i - 1]) return false;
    }
    return true;
}

int casT;

void run() {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    if (is_sorted(a + 1, a + 1 + n)) {
        printf("0");
        if (casT != 0) puts("");
        return;
    }
    if (m == 1) {
        printf("-2");
        if (casT != 0) puts("");
        return;
    }
    if (m == 2) {
        int pre = 1;
        while (pre < n && a[pre] <= a[pre + 1]) pre++;
        int suf = pre + 1;
        while (suf < n && a[suf] <= a[suf + 1]) suf++;
//        printf("%d %d\\n", pre, suf);
        if (suf != n || a[n] > a[1]) {
            printf("-2");
            if (casT != 0) puts("");
            return;
        } else {
            puts("1\\n2");
            printf("0 %d %d\\n", pre, n);
            printf("2 1");
            if (casT != 0) puts("");
            return;
        }
    }
    sort(b + 1, b + 1 + n);
    tot = unique(b + 1, b + 1 + n) - b - 1;
    ans.clear();
    for(int i = 1; i <= n; ++i) {
        c[i] = 0;
        G[i].clear();
    }
    for (int i = 1; i <= n; ++i) {
        id[i] = lower_bound(b + 1, b + 1 + tot, a[i]) - b;
        G[ id[i] ].push_back(i);
    }
//    printf("%d\\n", n);
    for (int i = tot; i >= 1; --i) {
        for (auto v : G[i]) {
            int pos = v;
            pos += ask(pos);
            if (pos == 1) continue;
//            printf("%d\\n", pos); 
            assert(pos >= 1 && pos <= n);
            ans.push_back(pos);
            add(1, 1);
            add(v, -1);
        }
    }
    printf("%d\\n", ans.size());
    int lst = ans.size();
    for (auto v : ans) {
        lst--;
        if (v == n) {
            puts("2");
            printf("0 %d %d\\n", v - 1, v);
            printf("2 1");
            if (lst != 0 || casT != 0) puts("");
        } else {
            puts("3");
            printf("0 %d %d %d\\n", v - 1, v, n);
            printf("2 1 3");
            if (lst != 0 || casT != 0) puts("");
        }
    }
}

int main() {
    scanf("%d", &casT);
    while (casT--) run();
    return 0;
} 

E

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double db;
const int N = 1e2+5;
const db pi = acos(-1);
const db eps = 1e-9;

struct P{
	db x,y;
	
	void read(){
		cin>>x>>y;
	}
	
	friend P operator - (P a,P b){
		return {a.x-b.x,a.y-b.y};
	}
	
	friend P operator + (P a,P b){
		return {(a.x+b.x)/2,(a.y+b.y)/2};
	}
	
	db deg(){
		db k=atan2(y,x);
		if(k<0)k+=2*pi;
		return k;
	}
	
	P rotate(double k){
		db x1=x,y1=y;
		double c=cos(k),s=sin(k);
		x=x1*c-y1*s;
		y=x1*s+y1*c;
	}
	
}a[N],b[N];

int n;
vector<db> v;
db ans[N][N];

int main(){
	cin>>n;
	for(int i=1;i<=n;++i)a[i].read(),b[i]=a[i];
	for(int c=1;c<=n;++c){
		v.clear();
		v.push_back(0);
		v.push_back(2*pi);
		for(int i=1;i<=n;++i)if(i!=c)
		for(int j=1;j<i;++j)if(j!=c){
			P t=a[i]-a[j];
			db w;
			w=pi/2-t.deg();
			if(w<0)w+=2*pi;
			v.push_back(w);
			w=pi*3/2-t.deg();
			if(w<0)w+=2*pi;
			v.push_back(w);
			
			t=a[i]+a[j];
			t=t-a[c];
			if(abs(t.x)<eps&&abs(t.y)<eps)continue;
			w=pi/2-t.deg();
			if(w<0)w+=2*pi;
			v.push_back(w);
			w=pi*3/2-t.deg();
			if(w<0)w+=2*pi;
			v.push_back(w);
		}
		sort(v.begin(),v.end());
		for(int j=1;j<=n;++j)a[j]=b[j];
		for(int i=1;i<v.size();++i){
			db det=(v[i]-v[i-1])/2;
			for(int j=1;j<=n;++j)a[j].rotate(det);
			int p=0;
			db res=0;
			for(int k=1;k<=n;++k)
			if(k!=c){
				P t=a[c]-a[k];
				if(!p||abs(t.x)<res-eps){
					p=k;
					res=abs(t.x);
				}
			}
			ans[c][p]+=det*2;
			for(int j=1;j<=n;++j)a[j].rotate(det);
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j)printf("%.11Lf ",ans[i][j]/2/pi);
		if(i!=n)printf("\\n");
	}
}
 

J

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

const int N = 5e6+5;
double h[505][10005],res[505][10005];
bool vis[505][10005];
int dx[] = {-1,0,1,0};
int dy[] = {0,1,0,-1};
int n,m;
struct node
{
	double h;
	int x,y;
};
vector<node>po;

bool check(int x,int y)
{
	return x>0 and x<=n and y>0 and y<=n;
}
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			cin>>h[i][j];
			res[i][j] = (double)m;
			po.push_back({h[i][j],i,j});
		}
	sort(po.begin(),po.end(),[](node a,node b){
		return a.h > b.h;
	});
	
	for(int i=0;i<po.size();i++)
	{
		int cnt = 0;
		int xx = po[i].x,yy = po[i].y;
		for(int j=0;j<4;j++)
		{
			int nx = xx+dx[j];
			int ny = yy+dy[j];
			if(!check(nx,ny)) continue;
			if(!vis[nx][ny] and po[i].h>h[nx][ny]) cnt++;
		}
		for(int j=0;j<4;j++)
		{
			int nx = xx+dx[j];
			int ny = yy+dy[j];
			if(!check(nx,ny)) continue;
			if(!vis[nx][ny] and po[i].h>h[nx][ny])
				res[nx][ny] += res[xx][yy]/cnt;
		}
		vis[xx][yy] = true;
	}
	for(int i=1

以上是关于2021 ICPC 网络赛2的主要内容,如果未能解决你的问题,请参考以下文章

2021icpc网络赛A题ac代码及思路

2021下半年ICPC各类赛事时间日程

2021 ICPC网络赛第一场

2021 icpc网络赛总结

2021ICPC网络赛第二场The 2021 ICPC Asia Regionals Online Contest (II) L Euler Function

ICPC 2021网络赛2The 2021 ICPC Asia Regionals Online Contest (II)签到题5题