ABC314 A-D、F

AtCoder Beginner Contest 314 - AtCoder

被期望薄纱了,E卡了一个多小时没啥有用的思路,F没看...后天补完题补上

A - 3.14

题意:

给出π的前100位,输出π保留小数点后n位(超过n位的直接删除)

题解:

签到!

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL N = 1e3 + 10, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
char ch[] = "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
void solve()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i <= n + 1; ++i)
		printf("%c", ch[i]);
}
int main()
{
	int T = 1;
	//scanf("%d", &T);
	while (T--)
	{
		solve();
	}
	return 0;
}

B - Roulette

题意:

有n人猜一个0到36的数字,第i个人猜了ci个数字分别为ai,1、ai,2...ai,ci。给出数字x,输出所有猜中数字x并且猜的数字数量最少的人的编号

题解:

先求出所有猜中数字x人中最少的猜的数的数量min,记录所有猜中数字x并且猜的数字数量为min的人的编号,输出。

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL N = 1e2 + 10, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
set<int>st[N];
void solve()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
		int x;
		scanf("%d", &x);
		for (int j = 1; j <= x; ++j)
		{
			int y;
			scanf("%d", &y);
			st[i].insert(y);
		}
	}
	int x, minn = INF;
	scanf("%d", &x);
	for (int i = 1; i <= n; ++i)
	{
		if (st[i].find(x) != st[i].end())
			minn = min(minn, (int)st[i].size());
	}
	vector<int>ans;
	for (int i = 1; i <= n; ++i)
	{
		if (st[i].find(x) != st[i].end() && st[i].size() == minn)
			ans.push_back(i);
	}
	printf("%d\n", ans.size());
	for (auto i : ans)
		printf("%d ", i);
}
int main()
{
	int T = 1;
	//scanf("%d", &T);
	while (T--)
	{
		solve();
	}
	return 0;
}

C - Rotate Colored Subsequence

题意:

给出一个长度为n的字符串s,每个字符都有一个颜色ci(1<=ci<=m)。对于每个字符都把它换成左边距离它最近的颜色相同的字符(若不存在则为颜色相同的最右的字符)。

题解:

分别存下每种颜色字符下标的集合然后模拟即可。

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL N = 2e5 + 10, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
vector<int>v[N];
char ch[N], ans[N];
void solve()
{
	int n, m;
	scanf("%d%d%s", &n, &m, ch + 1);
	for (int i = 1; i <= n; ++i)
	{
		int x;
		scanf("%d", &x);
		v[x].push_back(i);
	}
	for (int i = 1; i <= m; ++i)
	{
		int k = v[i].size();
		for (int j = 0; j < k; ++j)
		{
			ans[v[i][j]] = ch[v[i][(j - 1 + k) % k]];
		}
	}
	printf("%s", ans + 1);
}
int main()
{
	int T = 1;
	//scanf("%d", &T);
	while (T--)
	{
		solve();
	}
	return 0;
}

D - LOWER

题意:

给出一个长度为n的由小写或大写字母组成的字符串s,对该字符串进行q次操作(ti,xi,ci):1、ti=1时,将字符串种的第xi个字符换成ci,2、ti=2时,将字符串中的所有大写字母换成小写字母,3、ti=3时,将字符串中的所有小写字母换成大写字母。(对于ti=2,3的情况需要输入xi,ci但是不会被使用)

题解:

暴力模拟时,1操作时间复杂度O(1),2、3操作时间复杂度O(n)。而对于多次23操作时,仅有最后一次操作会起作用。所以我们可以记录23操作的数量后不执行不是最后一次的23操作,使得时间复杂度较大的23操作仅执行一次。

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#include<set>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL N = 5e5 + 10, MOD = 1e9 + 7, INF = 0x3f3f3f3f;
char ch[N], c[N];
int op[N], x[N];
void solve()
{
	int n, q, s = 0;
	scanf("%d%s%d", &n, ch + 1, &q);
	for (int i = 1; i <= q; ++i)
	{
		scanf("%d%d %c", &op[i], &x[i], &c[i]);
		if (op[i] != 1)++s;
	}
	for (int i = 1; i <= q; ++i)
	{
		if (op[i] == 1)ch[x[i]] = c[i];
		else if (!--s)
		{
			for (int j = 1; j <= n; ++j)
			{
				if (op[i] == 2 && ch[j] <= 'Z')
					ch[j] += 'a' - 'A';
				else if (op[i] == 3 && ch[j] >= 'a')
					ch[j] -= 'a' - 'A';
			}
		}
	}
	printf("%s", ch + 1);
}
int main()
{
	int T = 1;
	//scanf("%d", &T);
	while (T--)
	{
		solve();
	}
	return 0;
}

F - A Certain Game

题意:

有N个玩家,刚开始每个玩家都只与自己属于一个队伍。进行n-1场比赛:每场比赛都为人xi与人yi所属的队伍打一架,记队伍x的人数为sx,队伍y的人数为sy,则队伍x获证的概率为sx/(sx+sy),队伍y获胜的概率为sy/(sx+sy),并且在比赛后两个队伍将会合并。

求每个玩家所在队伍获胜场次的期望。

题解:

构造一颗这样的树:(图来自官解:解説 - AtCoder Beginner Contest 314

 对于每两个队伍打一架之后都记录那个队伍的获胜概率(即进计算那一场的胜场数期望值),然后新建一个节点(合并之后的新队伍),并用并查集维护每个人所属的队伍以及队伍的人数。这样建完树之后再从根往下给每个人加上他的胜场数期望就行了。很像克鲁斯卡尔重构树...

只能说...写过克鲁斯卡尔重构树就觉得出了思路之后写起来很顺。但是赛时没开到这题...

#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const LL N = 4e5 + 10, MOD = 998244353, INF = 0x3f3f3f3f;
LL e[N], idx;
vector<int>kids[N];
int p[N], s[N];
int find(int x)//并查集
{
	if (p[x] != x)
		p[x] = find(p[x]);
	return p[x];
}
LL qpow(LL x, LL y)//快速幂
{
	x %= MOD;
	if (y == 0)return 1;
	if (y % 2)
		return qpow(x * x, y / 2) * x % MOD;
	return qpow(x * x, y / 2) % MOD;
}
LL inv(LL x)//求逆元
{
	return qpow(x, MOD - 2);
}
void insert(int x, int y)
{
	x = find(x), y = find(y);//找到x,y所属的团队
	e[x] = s[x] * inv(s[x] + s[y]) % MOD;//计数团队获胜的概率
	e[y] = s[y] * inv(s[x] + s[y]) % MOD;
	p[x] = p[y] = ++idx;//新建一个新的团队
	kids[idx] = { x,y };//记录边
	s[idx] = s[x] + s[y];//更新新团队人数
}
void dfs(int u,int f)//从根往下搜一遍给每个人的胜率加上
{
	e[u] = (e[u] + e[f]) % MOD;
	for (auto v : kids[u])
		dfs(v, u);
}
void solve()
{
	int n;
	scanf("%d", &n);
	idx = n;//初始化新节点编号
	for (int i = 1; i <= 2 * n; ++i)
		p[i] = i, s[i] = 1;//初始化并查集
	for (int i = 1; i < n; ++i)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		insert(x, y);//xy所属团队打一架
	}
	dfs(idx, 0);//
	for (int i = 1; i <= n; ++i)
		printf("%lld ", e[i]);
}
int main()
{
	int T = 1;
	//scanf("%d", &T);
	while (T--)
	{
		solve();
	}
	return 0;
}

  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
更新说明: 2017-02-04(yaya) Ls command: Empty Folder returns false. 2016-12-08(yaya) 修正lz4、vhd不显示解压缩进度指示。增加lzma解压缩进度指示。 2016-11-09(不点) 0x8205 bit 5 = 1: 使checkkey闲置循环停止指令。 2016-04-13(yaya) 支持动画菜单 setmenu --graphic-entry=类型=菜单行数=菜单列数=图形宽(像素)=图形高(像素)=菜单行间距(像素) 菜单项0的路径文件名 类型: 位0:高亮指定颜色 位1:高亮颜色翻转 位2:高亮显示线框 位7:背景透明(最好使用黑色背景) 文件名: *n.??? 格式 n=00-99 高亮颜色由 color HIGHLIGHT=0xrrggbb 指定。 字符可以使用任意字型、字高、颜色,可以辅以图标。 2016-03-25(yaya) 菜单字符可以使用不同字型。 例如:"七" 使用不同字型,将 .hex 文件中的 unicode 码 “4e03” 修改为 “0080”, 将菜单中的 "七" 修改为 “\X0080”。 2016-03-23(yaya) 增强 echo 函数功能。 例如:echo -e \x18 显示 UTF-8 字符 0x18。 echo -e \X2191 显示 unicode 字符 0x2191。 2016-03-15(yaya) 1.增加动画控制热键 F2:播放/停止。 2.增加动画控制位 0x835b,位0:0/1=停止/播放。 3.增加精简字库模式:--simp=起始0,终止0,...,起始3,终止3 中文可以使用 --simp= ,内置字库应当包含 DotSize=[font_h],['simp'] 例如:font --font-high=24 --simp= /24_24.hex DotSize=24,simp 不使用热键: 可以加载 32*32 unifont 全字库 使用热键: 可以加载 24*24 unifont 全字库 使用精简字库: 可以加载 46*46 汉字全字库 使用精简字库及热键:可以加载 40*40 汉字全字库 4.不再支持 bin 格式字库。 2016-03-03(yaya) 1.增加图像背景色设置方法。 splashimage --fill-color=[0xrrggbb] 作用之一,作为小图像的背景。 作用之二,直接作为菜单的背景(即不加载图像背景)。此时只设置字体的前景色即可。 2.增加动画菜单。 splashimage --animated=[type]=[delay]=[last_num]=[x]=[y] START_FILE 类型[type]:bit 0-3: 播放次数 bit 4: 永远重复 bit 7: 透明背景 type=00:禁止播放 播放n次:序列图像各显示n次,时间独占。可作为启动前导、序幕。 永远重复:序列图像无限循环,时间与菜单共享。可作为菜单里的动画。 背景透明:即抠像。要求4角像素为背景色。 背景色最好为白色或黑色,这样可以去除一些灰色杂波。若是彩色背景,则应当非常干净。 提醒:请以16进制方式输入。否则易错。 延迟[delay]:序列图像之间的延迟。单位是滴答,即1/18.2秒。 序列数[last_num]:序列图像总数(2位数,从1开始计数)。 偏移[x]、[y]:图像偏移,单位像素。 起始图像文件 START_FILE 命名规则:*n.??? n: 1-9 或 01-99 或 001-999。 3.增加固定图像的背景色可以透明。 splashimage [--offset=[type]=[x]=[y]] FILE 类型[type]:bit 7: 透明背景 2016-02-14(yaya) setmenu 函数增加菜单项目背景短/满参数(默认短) 2016-01-19(yaya) splashimage 函数增加图像起始偏移(默认0) 2015-08-20(yaya) 1.支持非

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值