ABC326
我又来提供 low 算法了。
从 D 开始。
我们把 \(\text{A}\) 看成 \(1\),把 \(\text{B}\) 看成 \(2\),把 \(\text{C}\) 看成 \(3\)。
那么就可以想到状压,然后把每一行和每一列的情况状态即可。
#include<bits/stdc++.h>
using namespace std;
const int maxn = 6;
int row[maxn],col[maxn];
string ans[maxn];
int n;
string r,c;
int tot = 0;
void dfs(int x,int y)
{
if(x == n)
{
if(tot == 3 * n)
{
cout << "Yes\n";
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
cout << ans[i][j];
}
cout << '\n';
}
exit(0);//杀死程序
}
return ;
}
if(y == n)
{
dfs(x + 1,0);
return ;
}
dfs(x,y + 1);//填.
for(int i = 0;i < 3;i++)
{
if(row[x] == 0 && i + 'A' != r[x])
{
continue;
}
if(col[y] == 0 && i + 'A' != c[y])
{
continue;
}//这样可以保证题目所说的2,3条件
if(row[x] >> i & 1)
{
continue;
}
if(col[y] >> i & 1)
{
continue;
}//不可以填的情况
ans[x][y] = 'A' + i;
row[x] ^= 1 << i;
col[y] ^= 1 << i;
tot += 1;
dfs(x,y + 1);
ans[x][y] = '.';
row[x] ^= 1 << i;
col[y] ^= 1 << i;
tot -= 1;//回溯
}
}
int main()
{
cin >> n >> r >> c;
for(int i = 0;i < n;i++)
{
for(int j = 0;j < n;j++)
{
ans[i][j] = '.';
}
}
dfs(0,0);
cout << "No";
return 0;
}
\(\text{tot}\) 指的是总共有多少个数。
不难。
其实就是每一个数取到的概率乘上每一个数的值即可。
设取到 \(a_i\) 的概率为 \(p_i\),则有 \(p_i = \dfrac{1}{n} \sum^{i-1}_{j=0} p_j\)。
为什么呢?
因为 \(\dfrac{1}{n} p_j\) 表示 \(x=j\) 时骰子显示 \(i\) 的概率。
所以就可以在 \(O(n)\) 的时间内求出来。
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
int qpow(int a,int b)
{
int res = 1;
while(b)
{
if(b & 1)
{
res = res * a % mod;
}
a = a * a % mod;
b >>= 1;
}
return res;
}
int n;
signed main()
{
cin >> n;
int ans = 0,p = qpow(n,mod - 2);
for(int i = 1;i <= n;i++)
{
int a;
cin >> a;
ans = (p * a % mod + ans) % mod;
p = (p + p * qpow(n,mod - 2) % mod) % mod;
}
cout << ans << '\n';
return 0;
}
随机推荐
- HarmonyOS NEXT应用开发—在Native侧实现进度通知功能
介绍 本示例通过模拟下载场景介绍如何将Native的进度信息实时同步到ArkTS侧. 效果图预览 使用说明 点击"Start Download"按钮后,Native侧启动子线程模拟 ...
- 阿里云视觉智能开放平台正式上线,阿里集团核心视觉AI能力对外开放
1月底,阿里云正式推出以计算机视觉AI能力为核心的视觉智能开放平台(vision.aliyun.com),平台目前已上线8大类目,超过50多种视觉AI能力,面向人脸识别,文字识别,商品理解,内容安全, ...
- Spring Cloud Stream 体系及原理介绍
简介: Spring Cloud Stream在 Spring Cloud 体系内用于构建高度可扩展的基于事件驱动的微服务,其目的是为了简化消息在 Spring Cloud 应用程序中的开发. 作者 ...
- 浅谈RSocket与响应式编程
简介: RSocket是高效一个二进制的网络通讯协议,能够满足很多场景下使用.另外,RSocket也是一个激进的响应式捍卫者,激进到连API都跟响应式无缝集成.本文我们将和大家分享RSocket与响 ...
- [FAQ] Vue iframe 的 src 是链接地址却加载了相对路径 ?
iframe 的 src 是链接, 但是加载的实际链接是相对路径,只有一种可能:链接地址不正确. 检查链接有没有少符号,常见错误:http//,http:/ Refer:Vue的iframe错误 Li ...
- 2019-10-31-WPF-设置纯软件渲染
title author date CreateTime categories WPF 设置纯软件渲染 lindexi 2019-10-31 8:59:2 +0800 2018-04-20 16:36 ...
- 开发日记:中控PUSH协议
using System; using System.IO; using System.Net; using System.Text.RegularExpressions; namespace Con ...
- 登录信息localStorage存储
localStorage拓展了cookie的4K限制,与sessionStorage的唯一一点区别就是localStorage属于永久性存储,而sessionStorage属于当会话结束的时候,ses ...
- docker 完美部署gitea
效果: docker-compose version: "3" networks: gitea: external: false services: server: image: ...
- JS实现下拉框切换和tab标签切换
现在商城网页上会有下拉框切换内容,是如何实现的呢,研究了一天,在调整js代码和查找bug.最终完成了自己想要的效果,我没有写CSS样式,只是实现了基本功能,如果对你有所帮助,可以自己写css,使其更加 ...