Two Flowers CodeChef - TWOFL
https://vjudge.net/problem/CodeChef-TWOFL
先把颜色相同的合并成一个点,建好图,枚举要取的两种颜色(根据图中所有边决定哪些组合要枚举)即可
错误记录:
1.写了个假的对于诸如1 2 1 2这种数据只能找出3(前3个数)的答案的算法
2.46行写成(i-1)*n+m
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
#include<map>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;
int n,m;
int a[][],p[][];
int fa[],d[];
int sz[],sz2[];
bool vis[];
int num[],ta,ans;
int dx[]={,,,-};
int dy[]={,-,,};
int find(int x) {return x==fa[x]?x:fa[x]=find(fa[x]);}
vector<int> e[];
//set<pi> s;
map<pi,vector<pi>> ma;
//vector<int> s2[4000100];
vector<int> t;
void ins(int a,int b)
{
int ta=d[a],tb=d[b];
if(ta>tb) swap(ta,tb);
//s.insert(mp(ta,tb));
if(a>b) swap(a,b);
ma[mp(ta,tb)].pb(mp(a,b));
}
int main()
{
int i,j,k,fx,fy,x,y;
scanf("%d%d",&n,&m);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
scanf("%d",&a[i][j]);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
p[i][j]=(i-)*m+j,d[p[i][j]]=a[i][j];
for(i=;i<=n*m;i++) fa[i]=i,sz[i]=;
for(i=;i<=n;i++)
for(j=;j<=m;j++)
for(k=;k<;k++)
{
x=i+dx[k];y=j+dy[k];
if(x>=&&x<=n&&y>=&&y<=m&&a[i][j]==a[x][y])
{
fx=find(p[i][j]);fy=find(p[x][y]);
if(fx!=fy) fa[fy]=fx,sz[fx]+=sz[fy];
}
}
for(i=;i<=n;i++)
for(j=;j<=m;j++)
{
fx=find(p[i][j]);//s2[d[fx]].pb(fx);
for(k=;k<;k++)
{
x=i+dx[k];y=j+dy[k];
if(x>=&&x<=n&&y>=&&y<=m)
{
fy=find(p[x][y]);
if(fx!=fy) ins(fx,fy);
}
}
}
for(i=;i<=n*m;i++) fa[i]=i,sz2[i]=sz[i],ans=max(ans,sz[i]);
for(auto &xx:ma)
{
t.clear();
for(auto &yy:xx.se)
{
fx=find(yy.fi);fy=find(yy.se);
if(fx!=fy) fa[fx]=fy,sz2[fy]+=sz2[fx],ans=max(ans,sz2[fy]),t.pb(fx),t.pb(fy);
}
for(auto &tt:t) fa[tt]=tt,sz2[tt]=sz[tt];
}
printf("%d",ans);
return ;
}
Two Flowers CodeChef - TWOFL的更多相关文章
- 【BZOJ-3514】Codechef MARCH14 GERALD07加强版 LinkCutTree + 主席树
3514: Codechef MARCH14 GERALD07加强版 Time Limit: 60 Sec Memory Limit: 256 MBSubmit: 1288 Solved: 490 ...
- CF451E Devu and Flowers (隔板法 容斥原理 Lucas定理 求逆元)
Codeforces Round #258 (Div. 2) Devu and Flowers E. Devu and Flowers time limit per test 4 seconds me ...
- poj 3262 Protecting the Flowers
http://poj.org/problem?id=3262 Protecting the Flowers Time Limit: 2000MS Memory Limit: 65536K Tota ...
- Codeforces Round #381 (Div. 2)B. Alyona and flowers(水题)
B. Alyona and flowers Problem Description: Let's define a subarray as a segment of consecutive flowe ...
- poj1157LITTLE SHOP OF FLOWERS
Description You want to arrange the window of your flower shop in a most pleasant way. You have F bu ...
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- 【BZOJ4260】 Codechef REBXOR 可持久化Trie
看到异或就去想前缀和(⊙o⊙) 这个就是正反做一遍最大异或和更新答案 最大异或就是很经典的可持久化Trie,从高到低贪心 WA: val&(1<<(base-1))得到的并不直接是 ...
- 线段树或树状数组---Flowers
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Description As is known to all, the blooming tim ...
- sgu 104 Little shop of flowers 解题报告及测试数据
104. Little shop of flowers time limit per test: 0.25 sec. memory limit per test: 4096 KB 问题: 你想要将你的 ...
随机推荐
- (testng多个class文件执行时混乱,不是等一个class内的所有methods执行完再去执行下一个class内的内容)问题的解决
问题描述如下: We use TestNG and Selenium WebDriver to test our web application. Now our problem is that we ...
- 流媒体开发之开源项目live555---live555 server 编译 包括更改帧率大小
由于要测试8148解码器的性能,需要搭建不同帧率25fps - >30fps,宏块大小defualt 100 000 -> 200 000不同大小的h264码流,所以就需要编译改动的liv ...
- Region Range
三篇文章了解 TiDB 技术内幕 - 说存储| PingCAP https://pingcap.com/blog-cn/tidb-internal-1/ 对于一个 KV 系统,将数据分散在多台机器上有 ...
- XML-RPC JSON-RPC RPC是实现思路
XML-RPC - Wikipedia https://en.wikipedia.org/wiki/XML-RPC JSON-RPC - Wikipedia https://en.wikipedia. ...
- 解决pyspark-linux-windowsIDE JAVA_HOME not set
对 os.environ 赋值 ssh://root@192.168.2.51:22/usr/bin/python -u /home/data/tmp_test/trunk/personas/tmp_ ...
- update外联表,用另一个表数据更新本表数据
update s set s.classbid = lc.itemidfrom dbo.Lv_servers as s INNER JOIN dbo.Lv_LineChannel as lc O ...
- hihoCoder 1582 Territorial Dispute 【凸包】(ACM-ICPC国际大学生程序设计竞赛北京赛区(2017)网络赛)
#1582 : Territorial Dispute 时间限制:1000ms 单点时限:1000ms 内存限制:256MB 描述 In 2333, the C++ Empire and the Ja ...
- HTTP服务器用什么组件或者方式比较好
我目前用Indy的HttpServer组件来编写,但遇到一个暂时没有办法解决的问题,就是上传文件到这个HTTPServer,如果文件名包含中文,则会出现乱码.网上查了一下,这是个indy的遗留问题,据 ...
- MYSQL初级学习笔记三:数据的操作DML!(视频序号:初级_24,25,36)
知识点五:数据的操作DML(24,25,36) 插入数据: --测试插入记录INSERT CREATE TABLE IF NOT EXISTS user13( id TINYINT UNSIGNED ...
- 让th里面的东西自动换行
让th里面的东西自动换行 html中的TH里面的文字不管多长,始终是一行,很烦 <th style="word-wrap:break-word;">aaaaaaaaaa ...