D. Triangle Coloring
https://codeforces.com/contest/1795/problem/D
#include <iostream>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=3e5+10,mod=998244353;
int n;
ll qmi(ll a,ll k){
ll res=1;
while(k){
if(k&1) res=res*a%mod;
k>>=1;
a=a*a%mod;
}
return res;
}
bool fact(int a,int b,int c){
return a==b&&a<c&&b<c;
}
int main(){
ll res=1;
cin>>n;
ll k=1;
for(int i=1;i<=n;i+=3){
int x,y,z;
cin>>x>>y>>z;
if(x==y&&x==z) k=k*3%mod;
else if(fact(x,y,z)||fact(x,z,y)||fact(y,z,x)) k=k*2%mod;
}
for(int i=n/3,j=1;i>n/6;i--,j++){
res=res*i%mod;
res=res*qmi(j,mod-2)%mod;
}
res=res*k%mod;
cout<<res<<endl;
}
/*
就是每三个点一组,给所有数字染色,颜色只有红蓝,且一半染红一半染蓝
要想要使得结果最大
每个三原组有两种染法,红蓝蓝或者蓝红红
我们一共n/3个组,根据对称可得,n/6个得染红蓝蓝
另外有些特殊情况
例如当三个边权都一样时,就有三种情况
当两个边权一样且都是小边权时有两种情况
*/
D. Triangle Coloring的更多相关文章
- [LeetCode] Triangle 三角形
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
- [LeetCode] Pascal's Triangle II 杨辉三角之二
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...
- [LeetCode] Pascal's Triangle 杨辉三角
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Retur ...
- 【leetcode】Pascal's Triangle II
题目简述: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3, Retur ...
- 【leetcode】Pascal's Triangle
题目简述: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5 ...
- POJ 1163 The Triangle(简单动态规划)
http://poj.org/problem?id=1163 The Triangle Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- Triangle - Delaunay Triangulator
Triangle - Delaunay Triangulator eryar@163.com Abstract. Triangle is a 2D quality mesh generator an ...
- LeetCode 118 Pascal's Triangle
Problem: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows ...
- LeetCode 119 Pascal's Triangle II
Problem: Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- 【leetcode】Triangle (#120)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...
随机推荐
- Redefinition of 'y1' as different kind of symbol
Redefinition of 'y1' as different kind of symbol 原因 解释:此次定义的y1变量与函数库中定义的y1重名了,所以编译错误,重定义了y1变量. 解决方法: ...
- Keil 5(Keil C51)安装与注册 [ 图文教程 ]
前言 Keil C51 是 51 系列兼容单片机 C 语言软件开发系统,支持 8051 微控制器体系结构的 Keil 开发工具,适合每个阶段的开发人员,不管是专业的应用工程师,还是刚学习嵌入式软件开发 ...
- 【分析笔记】全志平台 gpio-keys 驱动应用和 stack crash 解决
内核配置 内核版本:Linux version 4.9.56 make ARCH=arm64 menuconfig Device Drivers ---> Input device suppor ...
- KingbaseES在线wal日志
KingbaseES数据库日志文件记录数据库的历史操作信息, 包含恢复数据库中的所有事务所需的信息. KingbaseES在线WAL日志: WAL日志: 预写式日志(Write-Ahead Loggi ...
- liinux-目录、文件结构及相关命令
1.前期必备知识 1.命令提示符 [root@max001 ~]#:root表示用户信息,max001表示主机名称. [root@max001 ~]%:普通用户结尾是$符号. 2.命令格式规范(语法规 ...
- C# 如何部分加载“超大”解决方案中的部分项目
在有的特有的项目环境下,团队会将所有的项目使用同一个解决方案进行管理.这种方式方面了管理,但是却会导致解决方案变得非常庞大,导致加载时间过长.那么,如何部分加载解决方案中的部分项目呢?就让我们来借用微 ...
- spring源码写注释
转:https://blog.csdn.net/z_c8819/article/details/105258015 1.从GitHub上下载spring项目 https://github.com/sp ...
- vs2019编写代码时的光标变成了黑块,选中字时替换掉了黑块选中的字的解决方法
这是由于不小心按到了Insert键 解决方法:再按一下Insert就好了. 因为插入键(insert)是一个状态表示键 当你按倒它时,它会进入一个覆盖模式,在光标位置新输入字会替代原来的字:另一种为插 ...
- 郁金香逆向 2.便利怪物对象数组 纯C写法
读取基础地址 获取节点数量 打印怪物列表 进行遍历 环环相扣
- 学习Vue过程中遇到的问题---code: 'MODULE_NOT_FOUND'
在学习安装脚手架Vue-cli过程中 步骤为: 第一步(仅第一次执行):全局安装@vue/cli. npm install -g @vue/cli 第二步:切换到你要创建项目的目录,然后使用命令创建项 ...