[POI2008]Sta

两遍DFS……

第一遍维护自己儿子到自己的

第二遍维护自己祖先到自己的

用了内嵌汇编……

//Lib
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<ctime>
 
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
//#include<stack>
#include<set>
#include<map>
using namespace std;
//Macro
#define rep(i,a,b)  for(int i=a,tt=b;i<=tt;++i)
#define drep(i,a,b) for(int i=a,tt=b;i>=tt;--i)
#define erep(i,e,x) for(int i=x;i;i=e[i].next)
#define irep(i,x)   for(__typeof(x.begin()) i=x.begin();i!=x.end();i++)
#define read()  (strtol(ipos,&ipos,10))
#define sqr(x)  ((x)*(x))
#define pb  push_back
#define PS  system("pause");
typedef long long   ll;
typedef pair<int,int> pii;
const int oo=~0U>>1;
const double inf=1e100;
const double eps=1e-6;
string name="", in=".in", out=".out";
//Var
struct E
{
    int node,next;
}e[2000008];
struct N
{
    long long up,down,size; 
}node[1000008];
int stack[20000000],bak;
char file[20000000],*ipos;
int h[1000008],n,tot;
void add(int a,int b){e[++tot].next=h[a];e[tot].node=b;h[a]=tot;}
void DFS1(int fa,int u)
{
    erep(i,e,h[u])
    {
        if(e[i].node!=fa)
        {
            DFS1(u,e[i].node);
            node[u].size+=node[e[i].node].size;
            node[u].down+=node[e[i].node].down;
        }
    }
    node[u].down+=node[u].size;
    node[u].size++;
}
void DFS2(int fa,int u)
{
    if(u!=1)node[u].up=node[fa].up+n-node[u].size+node[fa].down-(node[u].size+node[u].down);
    erep(i,e,h[u])
        if(e[i].node!=fa)DFS2(u,e[i].node); 
}
void CallDFS(void (*p)(int,int))
{
    __asm__ __volatile__
    (
        "mov %%esp,%0\n"
        "mov %1,%%esp\n"
        :"=g"(bak)
        :"g"(stack+20000000-1)
        :
    );
    (*p)(0,1);
    __asm__ __volatile__
    (
        "mov %0,%%esp\n"
        :
        :"g"(bak)
        :
    );  
}
void Work()
{
    fread(ipos=file,20000000,1,stdin);
    n=read();int a,b;
    rep(i,1,n-1)
    {
        a=read();b=read();
        add(a,b),add(b,a);
    }
    void (*p)(int,int)=DFS1;
    CallDFS(p);
    p=DFS2;
    CallDFS(p);
    int pos=1;
    rep(i,1,n)if(node[i].up+node[i].down>node[pos].up+node[pos].down)pos=i;
    cout<<pos<<endl;    
}
int main()
{
//  freopen((name+in).c_str(),"r",stdin);
//  freopen((name+out).c_str(),"w",stdout);
//  Init();
    Work();
    return 0;
}


POI本身并没有直接给插入的Excel图片添加边框的方法,但可以通过一些变通的方式来实现类似效果,以下是一个示例代码: ```java import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.*; import org.springframework.core.io.ClassPathResource; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.IOException; public class AddBorderToImageInExcel { public static void main(String[] args) throws IOException { HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Sheet1"); // 先把读进来的图片放到一个ByteArrayOutputStream中,以便产生ByteArray ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); BufferedImage bufferImg = null; try { // 读取图片 ClassPathResource resource = new ClassPathResource("static/acc_sta_logo.png"); bufferImg = ImageIO.read(resource.getInputStream()); // 将图片写入流中 ImageIO.write(bufferImg, "png", byteArrayOut); // 利用HSSFPatriarch将图片写入EXCEL HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); // 图片导出到单元格B2中 HSSFClientAnchor anchor = new HSSFClientAnchor(350, 100, 150, 0, (short) 0, 0, (short) 1, 2); // 插入图片 patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_PNG)); // 创建一个有边框的单元格样式 CellStyle borderStyle = wb.createCellStyle(); borderStyle.setBorderTop(BorderStyle.THIN); borderStyle.setBorderBottom(BorderStyle.THIN); borderStyle.setBorderLeft(BorderStyle.THIN); borderStyle.setBorderRight(BorderStyle.THIN); // 获取图片所在单元格范围并设置边框样式 Row row1 = sheet.getRow(anchor.getRow1()); if (row1 == null) { row1 = sheet.createRow(anchor.getRow1()); } Cell cell1 = row1.getCell(anchor.getCol1()); if (cell1 == null) { cell1 = row1.createCell(anchor.getCol1()); } cell1.setCellStyle(borderStyle); Row row2 = sheet.getRow(anchor.getRow2()); if (row2 == null) { row2 = sheet.createRow(anchor.getRow2()); } Cell cell2 = row2.getCell(anchor.getCol2()); if (cell2 == null) { cell2 = row2.createCell(anchor.getCol2()); } cell2.setCellStyle(borderStyle); } catch (IOException e) { e.printStackTrace(); } // 保存文件 FileOutputStream fileOut = new FileOutputStream("workbook.xls"); wb.write(fileOut); fileOut.close(); wb.close(); } } ``` 上述代码通过创建一个带有边框样式的单元格,将图片所在的单元格设置为该样式,从而实现给图片添加边框的效果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值