惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
人人都是产品经理
人人都是产品经理
爱范儿
爱范儿
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
H
Hackread – Cybersecurity News, Data Breaches, AI and More
B
Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Help Net Security
B
Blog RSS Feed
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
N
Netflix TechBlog - Medium
S
SegmentFault 最新的问题
The Cloudflare Blog
I
InfoQ
美团技术团队
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
L
LangChain Blog
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔
SGU 208. Toral Tickets
2023-05-11 · via 某岛

May 11, 2023

题意

给定一个 n∗m 的单面方格纸,然后把方格纸的长边卷起来,卷成一个圆柱体,再把收尾也接起来,形成一个 torus。求对格点进行黑白染色的方案数。

https://upload.wikimedia.org/wikipedia/commons/6/60/Torus_from_rectangle.gif

分析

Polya 计数,数据范围很小,暴力做循环分解即可。
难点是对于 n == m 的情况,要考虑 rt90()。

#include <lastweapon/bignum>
using namespace lastweapon;

const int N = 20;
int a[N][N], b[N][N]; bool v[N][N];
int n, m; bignum z;

int f(){
	int z = 0; RST(v);
	REP(i, n) REP(j, m) if (!v[i][j]) {
        int x = i, y = j;  do {
            v[x][y] = true;  int t = a[x][y];
            x = t / m, y = t % m;
        } while (!v[x][y]);
        ++z;
    }
	return z;

}

void rt90(){
	CPY(b, a); REP(i, n) REP(j, m) a[j][n-i-1] = b[i][j];
	swap(n, m);
}

void rt180(){
	rt90(); rt90();
}

void rolln(){
	CPY(b, a); REP(i, n) REP(j, m) a[i][j] = b[(i+1)%n][j];
}

void rollm(){
	CPY(b, a); REP(i, n) REP(j, m) a[i][j] = b[i][(j+1)%m];
}

void init(){
	REP(i, n) REP(j, m) a[i][j] = i*m + j; z = 0;
}

void Polay(){
	if (n==m){
		for (int k=0;k<4;k++,rt90())
			for (int i=0;i<n;i++,rolln())
				for (int j=0;j<m;j++,rollm())
					z += pow(bignum(2), f());
		z /= 4*n*m;
	}
	else {
		for (int k=0;k<2;k++,rt180())
			for (int i=0;i<n;i++,rolln())
				for (int j=0;j<m;j++,rollm())
					z += pow(bignum(2), f());
		z /= 2*n*m;
	}
}

int main() {

#ifndef ONLINE_JUDGE
    //freopen("in.txt", "r", stdin);
#endif

    while (scanf("%d %d", &n, &m) != EOF){
		init(); Polay();
		cout << z << endl;
	}
}

Posted by xiaodao
Category: 日常