Two Graphs

链接:https://www.nowcoder.com/acm/contest/139/D
 

题目描述

Two undirected simple graphs and where are isomorphic when there exists a bijection on V satisfying  if and only if {x, y} ∈ E2.
Given two graphs and , count the number of graphs satisfying the following condition:
* .
* G1 and G are isomorphic.

输入描述:

The input consists of several test cases and is terminated by end-of-file.
The first line of each test case contains three integers n, m1 and m2 where |E1| = m1 and |E2| = m2.
The i-th of the following m1 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E1.
The i-th of the last m2 lines contains 2 integers ai and bi which denote {ai, bi} ∈ E2.

输出描述:

For each test case, print an integer which denotes the result.

示例1

输入

复制

3 1 2
1 3
1 2
2 3
4 2 3
1 2
1 3
4 1
4 2
4 3

输出

复制

2
3

备注:

* 1 ≤ n ≤ 8
* 
* 1 ≤ ai, bi ≤ n
* The number of test cases does not exceed 50.

题意:

就是在E2中选择某些边构成G1的同构,问几种方法

分析:

暴力深搜

代码:

#include<bits/stdc++.h>
using namespace std;

int n,m1,m2,a,b;
int look[10][10],vis[10][10],pre[10],w[10],ans;
map<long long,int>mm;

struct AA
{
    int x,y;
}pos[50];

int dfs(int rt,long long pp)
{
    if(rt==n+1)
    {
        long long pp=0;
        for(int i=1;i<=m1;i++)
        {
            if(vis[pre[pos[i].x]][pre[pos[i].y]]==0) return 0;
            pp|=1<<vis[pre[pos[i].x]][pre[pos[i].y]];
        }
        if(mm[pp]) return 0;//判断选择的E2的边是否重复
        ans++;
        mm[pp]=1;
        return 0;
    }
    for(int i=1;i<=n;i++)
    {
        if(w[i]) continue;
        pre[rt]=i;//映射E1中的rt代表E2中的i
        w[i]=1;
        dfs(rt+1,pp*10+i);
        w[i]=0;
    }
    return 0;
}
int main()
{
    while(~scanf("%d%d%d",&n,&m1,&m2))
    {
        mm.clear();
        memset(look,0,sizeof(look));
        memset(vis,0,sizeof(vis));
        memset(w,0,sizeof(w));
        ans=0;
        for(int i=1;i<=n;i++)
        {
            pre[i]=i;
        }
        int x,y;
        for(int i=1;i<=m1;i++)
        {
            scanf("%d%d",&x,&y);
            look[x][y]=look[y][x]=1;
            pos[i].x=x;
            pos[i].y=y;
        }
        for(int i=1;i<=m2;i++)
        {
            scanf("%d%d",&x,&y);
            vis[x][y]=vis[y][x]=i;
        }
        dfs(1,0);
        printf("%d\n",ans);
    }
    return 0;
}

 

<think>好的,用户问的是如何在Stata中使用twoway画图让图表更好看。我需要一步步来思考如何回答这个问题。首先,用户可能对Stata的基础绘图有一定了解,但希望提升图表的美观度和专业性。接下来,我需要回忆Stata中twoway的命令选项以及常见的图形美化技巧。 首先,基础命令结构。用户可能已经知道基本的twoway语法,比如scatter、line等,但可能需要更详细的参数调整。比如,使用scheme选项来改变整体主题,比如s1mono或s2color,这样图表看起来更现代。 然后是坐标轴调整。坐标轴的标签、刻度、范围都是影响图表美观的重要因素。可能需要提到如何用xlabel和ylabel来设置刻度标签,xtitle和ytitle来修改轴标题,以及xscale和yscale调整范围。例如,避免自动范围导致的留白过多或数据被截断。 接下来是图例的优化。默认的图例位置可能不太合适,需要指导用户如何用legend()选项调整位置,比如放在图表下方或右侧,或者去掉重复的图例。同时,简化图例文本,使其更清晰。 颜色和标记样式也很重要。Stata默认的颜色可能不够美观,可以建议使用palette选项选择更协调的颜色组合,或者手动指定颜色代码。对于散点图,调整marker的符号、大小和颜色,线图的线宽、线型等,可以提升可读性。 添加辅助元素,比如标题、副标题、注释,这些能帮助解释图表内容。使用title()、subtitle()、note()等选项,但要注意不要过多,保持简洁。另外,添加参考线或区域,比如xline或yline,突出特定数值。 多图形组合也是一个要点,twoway支持叠加多个图形元素,比如同时显示散点图和拟合线,或者分面板绘图(by()选项),但需要合理布局避免混乱。 输出格式方面,保存图表时推荐使用高分辨率的PNG或矢量图PDF,确保在不同媒介上显示清晰。同时,调整图像尺寸以适应发布需求。 最后,可能需要提到一些高级技巧,比如自定义scheme,或者结合graph combine命令组合多个图表,以及利用Stata的图形编辑器进行微调,虽然编程实现更有利于复现性。 在整理这些点时,要确保结构清晰,分点说明,每个部分给出具体的示例代码,用中文解释每个选项的作用。同时,提醒用户注意常见错误,比如过度修饰导致图表难以理解,保持简洁和信息的清晰传达。</think>在Stata中使用 `twoway` 绘制美观图表,需结合代码优化和设计原则。以下是分步优化建议: --- ### 一、基础命令结构 ```stata twoway (scatter y x) (lfit y x), /// title("标题") subtitle("副标题") /// note("数据来源: XXX") /// scheme(s1mono) // 主题风格 ``` **说明**:`scheme()` 是核心美化参数,推荐 `s1mono`(简洁商务风)、`s2color`(默认彩色)、`s1rcolor`(期刊风格)等。 --- ### 二、坐标轴优化 ```stata xlabel(0(10)100, grid gmin gmax) // 刻度从0到100,间隔10,添加参考线 ylabel(, angle(0) format(%9.2f)) // 标签水平显示,保留两位小数 xtitle("X轴名称", size(medlarge)) // 字体大小调整 yscale(range(0 50) titlegap(2)) // 强制Y轴范围为0-50,标题间距 ``` **技巧**:`grid` 添加网格线,`nogrid` 可取消;`angle(0)` 避免标签倾斜。 --- ### 三、图例与颜色 ```stata legend(pos(6) cols(1) region(lcolor(white))) // 图例放在底部,单列,白边框 scatter y x, mcolor("#1f77b4") msize(small) // 手动指定颜色(十六进制)和标记大小 lfit y x, lcolor(red) lwidth(thick) lpattern(dash) // 红色虚线,加粗 ``` **调色方案**:使用 `colorpalette` 包扩展颜色选择,或参考 [Stata调色指南](https://blog.stata.com/2016/07/11/using-color-in-stata-graphs/)。 --- ### 四、叠加图形元素 ```stata twoway (scatter y x, mcolor(blue%50)) // 半透明散点 (lpoly y x, lcolor(black) band(5)) // 局部多项式拟合 (lowess y x, lcolor(red)), // LOWESS平滑曲线 xline(30, lcolor(gray) lpattern(dot)) // 垂直参考线 yline(0, lwidth(vthin)) // 水平细线 ``` --- ### 五、输出与格式 ```stata graph export "figure.png", width(2000) height(1200) // 高分辨率输出 graph set window fontface "Times New Roman" // 统一字体 ``` **格式建议**:学术论文推荐PDF(矢量图),演示用PNG(分辨率≥300dpi)。 --- ### 六、完整示例 ```stata use auto, clear twoway (scatter price mpg, mcolor("#2ca02c") msymbol(Oh) jitter(3)) (qfit price mpg, lcolor(maroon) lwidth(medthick)), title("汽车价格与油耗关系", size(medium)) subtitle("带二次拟合曲线", color(gray)) xtitle("每加仑里程数 (mpg)", margin(medium)) ytitle("价格 (美元)", margin(medium)) legend(off) scheme(s1mono) graph export "price_mpg.png", replace width(2000) ``` --- ### 注意事项: 1. **简洁性**:避免过度添加元素(如双网格线、冗余图例) 2. **一致性**:同一系列图表保持相同配色和字体 3. **可读性**:坐标轴标签避免科学计数法(用 `format(%9.0fc)` 格式化千分位) 4. **交互调整**:右键点击图表使用 `Graph Editor` 微调细节(但代码化更可复现)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值