2020年ICPC南京站 补题记录

A - Ah, It’s Yesterday Once More(构造)

  • 奇妙构造。。。总的来说就是斜着,下面是出题人给的方案
    在这里插入图片描述
#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define double long double
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<PII, int> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 2e5 + 10;
const int maxn = 1e6;
const int MAXN = 100;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	cout << 20 << ' ' << 20 << '\n';
	cout << "11111011111011111011\n";
	cout << "00101100101100101101\n";
	cout << "10110110110110110111\n";
	cout << "10011011011011011001\n";
	cout << "11101101101101101101\n";
	cout << "10110110110110110110\n";
	cout << "11011011011011011011\n";
	cout << "01101101101101101101\n";
	cout << "10110110110110110111\n";
	cout << "10011011011011011001\n";
	cout << "11101101101101101101\n";
	cout << "10110110110110110110\n";
	cout << "11011011011011011011\n";
	cout << "01101101101101101101\n";
	cout << "10110110110110110111\n";
	cout << "10011011011011011001\n";
	cout << "11101101101101101100\n";
	cout << "10110110110110110111\n";
	cout << "11011010011010011001\n";
	cout << "01101111101111101111\n";
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t = 1;
	// cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}

E - Evil Coordinate(构造)

  • 首先如果起点或者终点就是地雷,那一定没有方案
  • 记录每个方向的次数,左右和上下都可以抵消,之后左右和上下都只剩下一个方向,判断一下画个矩形就行了
  • 有个特殊情况就是如果最后只剩下一个方向,且只走这一个方向会遇到地雷,可以利用另外的方向避开这个地雷(说起来有点抽象,看代码即可)
#include <bits/stdc++.h>

using namespace std;

// #define int long long
#define double long double
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<PII, int> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 6e6 + 10;
const int maxn = 1e6;
const int MAXN = 100;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int xx, yy; cin >> xx >> yy;
	string s; cin >> s;
	bool lr = 0, ud = 0;
	if (xx == 0 && yy == 0)
	{
		cout << "Impossible\n";
		return;
	}
	vector<int> cnt(4); // UDLR
	int nowx = 0, nowy = 0;
	bool flag = false;
	for (auto t : s)
	{
		if (t == 'U')
		{
			nowy ++ ;
			cnt[0] ++ ;
		}
		else if (t == 'D')
		{
			nowy -- ;
			cnt[1] ++ ;
		}
		else if (t == 'L')
		{
			nowx -- ;
			cnt[2] ++ ;
		}
		else
		{
			nowx ++ ;
			cnt[3] ++ ;
		}
		if (nowx == xx && nowy == yy) flag = true;
	}
	if (cnt[0] && cnt[1]) ud = true;
	if (cnt[2] && cnt[3]) lr = true;
	if (!flag) cout << s << '\n';
	else
	{
		if (nowx == xx && nowy == yy) cout << "Impossible\n";
		else
		{
			string ans = "";
			if (cnt[0] > cnt[1])
			{
				if (!(xx == 0 && yy == 1)) for (int i = 0; i < cnt[1]; i ++ ) ans += "UD";
				else for (int i = 0; i < cnt[1]; i ++ ) ans += "DU";
				cnt[0] -= cnt[1], cnt[1] = 0;
			}
			else
			{
				if (!(xx == 0 && yy == 1)) for (int i = 0; i < cnt[0]; i ++ ) ans += "UD";
				else for (int i = 0; i < cnt[0]; i ++ ) ans += "DU";
				cnt[1] -= cnt[0], cnt[0] = 0;
			}
			if (cnt[2] > cnt[3])
			{
				if (!(xx == -1 && yy == 0)) for (int i = 0; i < cnt[3]; i ++ ) ans += "LR";
				else for (int i = 0; i < cnt[3]; i ++ ) ans += "RL";
				cnt[2] -= cnt[3], cnt[3] = 0;
			}
			else
			{
				if (!(xx == -1 && yy == 0)) for (int i = 0; i < cnt[2]; i ++ ) ans += "LR";
				else for (int i = 0; i < cnt[2]; i ++ ) ans += "RL";
				cnt[3] -= cnt[2], cnt[2] = 0;
			}

			auto check1 = [&]()
			{
				int x = 0, y = 0;
				
				for (int i = 0; i < cnt[2]; i ++ )
				{
					x -- ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[3]; i ++ )
				{
					x ++ ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[0]; i ++ )
				{
					y ++ ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[1]; i ++ )
				{
					y -- ;
					if (xx == x && yy == y) return false;
				}
				return true;
			};

			auto check2 = [&]()
			{
				int x = 0, y = 0;
				
				for (int i = 0; i < cnt[0]; i ++ )
				{
					y ++ ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[1]; i ++ )
				{
					y -- ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[2]; i ++ )
				{
					x -- ;
					if (xx == x && yy == y) return false;
				}
				for (int i = 0; i < cnt[3]; i ++ )
				{
					x ++ ;
					if (xx == x && yy == y) return false;
				}
				return true;
			};

			// 先左右后上下
			if (check1())
			{
				for (int i = 0; i < cnt[2]; i ++ ) ans += 'L';
				for (int i = 0; i < cnt[3]; i ++ ) ans += 'R';
				for (int i = 0; i < cnt[0]; i ++ ) ans += 'U';
				for (int i = 0; i < cnt[1]; i ++ ) ans += 'D';
			}
			else if (check2()) // 先上下后左右
			{
				for (int i = 0; i < cnt[0]; i ++ ) ans += 'U';
				for (int i = 0; i < cnt[1]; i ++ ) ans += 'D';
				for (int i = 0; i < cnt[2]; i ++ ) ans += 'L';
				for (int i = 0; i < cnt[3]; i ++ ) ans += 'R';
			}
			else
			{
				int tt = 0;
				for (int i = 0; i < 4; i ++ ) tt += (cnt[i] > 0);
				if (tt != 1)
				{
					cout << "Impossible\n";
					return;
				}
				else
				{
					if (cnt[0] > 0 || cnt[1] > 0)
					{
						if (!lr)
						{
							cout << "Impossible\n";
							return;
						}
						ans.pop_back(), ans.pop_back();
						ans += 'L';
						for (int i = 0; i < cnt[0]; i ++ ) ans += 'U';
						for (int i = 0; i < cnt[1]; i ++ ) ans += 'D';
						ans += 'R';
					}
					else
					{
						if (!ud)
						{
							cout << "Impossible\n";
							return;
						}
						for (int i = 0; i + 2 < ans.size(); i ++ ) ans[i] = ans[i + 2];
						ans.pop_back(), ans.pop_back();
						ans += 'U';
						for (int i = 0; i < cnt[2]; i ++ ) ans += 'L';
						for (int i = 0; i < cnt[3]; i ++ ) ans += 'R';
						ans += 'D';
					}
				}
			}
			cout << ans << '\n';
		}
	}
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

F - Fireworks(概率+三分)

  • 数学渣,偷个队友的码
#include<cstdio>
int n,m,p;
long double pow(long double n,long long m)
{
    if(m==0) return 1;
    long double fl=pow(n,m/2);
    fl*=fl;
    if(m&1) fl*=n;
    return fl;
}
long double F(long long k)
{
    long double a=(long double)n*k+m;
    long double b=1-pow(1-(long double)0.0001*p,k);
    return a/b;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d",&n,&m,&p);
        long long f=1,l=1e16;
        while(f<l)
        {
            long long dt=(l-f)/3;
            long long mid1=f+dt,mid2=f+dt*2;
            long double val1=F(mid1),val2=F(mid2);
            if(val1>val2) f=mid1+1;
            else l=mid2;
        }
        f-=500;
        if(f<=0) f=1;
        long double ans=1e300;
        ans = F(l);
        for(long long i=f;i<=f+1000;i++)
        {
            long double get=F(i);
            if(get<ans) ans=get;
        }
        if(f>1) 
        {
            if(F(f-1)<F(f))
            while(1)
            {
                f++;
            }
        }
        if(F(f+1000+1)<F(f+1000))
        {
            while(1)
            {
                f++;
            }
        }
        printf("%.10lf\n",(double)ans);
    }
    return 0;
}

H - Harmonious Rectangle(打表)

  • 小数据打表 大数据直接pow(3, n*m)
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
int ans[100][100]={{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0,0,0,0,0},{0,0,15,339,4761,52929,517761,4767849,43046721,387420489,486784380,381059392,429534507},{0,0,339,16485,518265,14321907,387406809,460338013,429534507,597431612,130653412,527642103,246336683},{0,0,4761,518265,43022385,486780060,429534507,792294829,175880701,246336683,953271190,214965851,412233812},{0,0,52929,14321907,486780060,288599194,130653412,748778899,953271190,644897553,710104287,555340537,947749553},{0,0,517761,387406809,429534507,130653412,246336683,579440654,412233812,518446848,947749553,909419307,966670169},{0,0,4767849,460338013,792294829,748778899,579440654,236701429,666021604,589237756,662963356,900849429,157687433},{0,0,43046721,429534507,175880701,953271190,412233812,666021604,767713261,966670169,322934415,772681989,566494346},{0,0,387420489,597431612,246336683,644897553,518446848,589237756,966670169,968803245,954137859,295347237,319625180},{0,0,486784380,130653412,953271190,710104287,947749553,662963356,322934415,954137859,886041711,876626606,924095353},{0,0,381059392,527642103,214965851,555340537,909419307,900849429,772681989,295347237,876626606,772286045,155055959},{0,0,429534507,246336683,412233812,947749553,966670169,157687433,566494346,319625180,924095353,155055959,93330098}};
int ksm(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1)
			res = res * a % mod;
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}
signed main()
{
	int T;
    scanf("%lld",&T);
    while(T--)
    {
        int n,m;
        scanf("%lld%lld",&n,&m);
        if(n<=10&&m<=10) printf("%lld\n",ans[n][m]);
        else if (n == 1 || m == 1) printf("%lld\n", 0ll);
        else printf("%lld\n",ksm(3,n*m));
    }
    return 0;
}

K - K Co-prime Permutation(签到)

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

int a[1000005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    // scanf("%d%d",&n,&k);
    cin >> n >> k;
    for(int i=1;i<=n;i++)
        a[i]=i;
    if(k==0) cout << -1;
    else
    {
        for(int i=1;i<k;i++)
            a[i]=a[i+1];
        a[k]=1;
        for(int i=1;i<=n;i++){
            // printf("%d ",a[i]);
            cout << a[i] << ' ';
        }
    }
    return 0;
}

L - Let’s Play Curling(贪心+签到)

#include <bits/stdc++.h>

using namespace std;

// #define int long long
#define double long double
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<PII, int> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 6e6 + 10;
const int maxn = 1e6;
const int MAXN = 100;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int n, m; cin >> n >> m;
	vector<PII> a(n + m + 1);
	set<int> st;
	for (int i = 1; i <= n; i ++ )
	{
		cin >> a[i].first;
		a[i].second = 0;
	}
	for (int i = n + 1; i <= n + m; i ++ )
	{
		cin >> a[i].first;
		a[i].second = 1;
		st.insert(a[i].first);
	}
	sort(a.begin() + 1, a.end());
	int ans = 0, tmp = 0;
	for (int i = 1; i <= n + m; i ++ )
	{
		if (a[i].second == 0)
		{
			if (st.count(a[i].first) == 0) tmp ++ ;
		}
		else
		{
			ans = max(ans, tmp);
			tmp = 0;
		}
	}
	ans = max(ans, tmp);
	if (ans == 0) cout << "Impossible\n";
	else cout << ans << '\n';
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

M - Monster Hunter(树形dp)

#include <bits/stdc++.h>
#include <bits/extc++.h>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define double long double
using i64 = long long;

typedef pair<int, int> PII;
typedef pair<int, char> PIC;
typedef pair<double, double> PDD;
typedef pair<PII, int> PIII;
typedef pair<int, pair<int, bool>> PIIB;

const int N = 2e5 + 10;
const int maxn = 1e6;
const int MAXN = 100;
const int mod = 998244353;
const int mod1 = 954169327;
const int mod2 = 906097321;
const int INF = 0x3f3f3f3f3f3f3f3f;

void solve()
{
	int n; cin >> n;
	vector<vector<int>> g(n + 1);
	for (int i = 2; i <= n; i ++ )
	{
		int x; cin >> x;
		g[i].push_back(x);
		g[x].push_back(i);
	}
	vector<int> a(n + 1), sz(n + 1);
	for (int i = 1; i <= n; i ++ ) cin >> a[i];
	vector<vector<vector<int>>> dp(2, vector<vector<int>>(n + 1, vector<int>(n + 1, INF)));
	function<void(int, int)> dfs = [&](int u, int fa)
	{
		dp[0][u][0] = 0;
		dp[1][u][1] = a[u];

		for (int i = 0; i < g[u].size(); i ++ )
		{
			int j = g[u][i];
			if (j == fa) continue;
			dfs(j, u);
		}

		sz[u] = 1;
		for (int i = 0; i < g[u].size(); i ++ )
		{
			int v = g[u][i];
			if (v == fa) continue;
			for (int j = sz[u]; j >= 0; j -- )
			{
				for (int k = sz[v]; k >= 0; k -- )
				{
					dp[0][u][j + k] = min(dp[0][u][j + k], dp[0][u][j] + min(dp[0][v][k], dp[1][v][k]));
					dp[1][u][j + k] = min(dp[1][u][j + k], dp[1][u][j] + min(dp[0][v][k], dp[1][v][k] + a[v]));
				}
			}
			sz[u] += sz[v];
		}
	};
	dfs(1, -1);
	for (int i = 0; i <= n; i ++ )
	{
		if (i != 0) cout << ' ';
		cout << min(dp[0][1][n - i], dp[1][1][n - i]);
	}
	cout << '\n';
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	int t = 1;
	cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}
  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Texcavator

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值