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 ...
随机推荐
- Redis缓存的主要异常及解决方案
作者:京东物流 陈昌浩 1 导读 Redis 是当前最流行的 NoSQL数据库.Redis主要用来做缓存使用,在提高数据查询效率.保护数据库等方面起到了关键性的作用,很大程度上提高系统的性能.当然在使 ...
- python学习第六周总结
封装 封装:就是将数据和功能'封装'起来 隐藏:在类的定义阶段名字前面使用两个下划线表示隐藏.就是将数据和功能隐藏起来不让用户直接调用,而是开发一些接口间接调用,从而可以在接口内添加额外的操作 伪装: ...
- 真正“搞”懂HTTP协议14之HTTP3
我们前一篇学习了HTTP/2,相比于HTTP/1,HTTP/2在性能上有了大幅的改进,但是HTTP/2因为底层还是基于TCP协议的,虽然HTTP/2在应用层引入了流的概念,利用多路复用解决了队头阻塞的 ...
- 线程基础知识16-线程相关类CyclicBarrier、Semaphore、Exchanger
1 CyclicBarrier 1.1 作用 从字面上的意思可以知道,这个类的中文意思是"循环栅栏".大概的意思就是一个可循环利用的屏障. 它的作用就是会让所有线程都等待完成后才会 ...
- app实现外部浏览器打开链接
需求:安卓和IOS开发的混合app.前端使用vue,vant2,安卓使用java,ios使用的object-c.实现效果:点击按钮,下载PDF附件,app跳转到手机外部浏览器,下载附件...... 1 ...
- HGAME_2023_WEB_WP_WEEK3
Ping to the host 很明显的rce,简单测试一下发现空格,cat,:被办,且执行无回显,空格用${IFS},%09,$IFS$9等等来绕过,我们利用dnslog将执行结果外带出来,这里使 ...
- 上篇 | 使用 🤗 Transformers 进行概率时间序列预测
介绍 时间序列预测是一个重要的科学和商业问题,因此最近通过使用基于深度学习 而不是经典方法的模型也涌现出诸多创新.ARIMA 等经典方法与新颖的深度学习方法之间的一个重要区别如下. 概率预测 通常,经 ...
- 以docker方式部署的redis键值查询及清理
1.首先使用 docker ps 命令来查看正在运行的容器.该命令会列出容器的ID.名称.端口号.状态等信息.也可以使用 docker ps -a 命令来查看所有容器,包括已经停止的容器. docke ...
- Naughty Stone Piles
题目:http://codeforces.com/problemset/problem/227/D 题意:n堆个数石子,每堆石子有ai个,通过合并(即将一堆石子移到另一堆石子上),将所有石子合并为一堆 ...
- Linux(CentOS)安装MinIo,详细教程,附防火墙端口开放操作
Linux安装MinIo(已配置开机重启) 1,准备安装目录和文件 系统:CentOs #进入安装目录 cd /home/minio #在线下载二进制文件 wget https://dl.min.io ...