主要利用了宏和stderr...

#define enable_debug
#ifdef enable_debug
FILL some macros/functions here
#else
/// set some debug functions to NULL
#endif

1. 输出到stderr

#define debug(...) { \
fprintf(stderr,__VA_ARGS__); \
fflush(stderr); \
} \

2. 若debug则插入一段代码

#define ProgDBG(...) { __VA_ARGS__; }

example.

#include "cstdio"
#include "vector"
#include "cstring"
#include "cstdlib"
#include "algorithm"
#define pb push_back
#define frp(x,y,z) freopen(#x"."#z,#y,std##z);
using namespace std;
const int
maxn = 50010,
maxm = 100010; struct node;
struct ed{
node*f,*t;
ed*r;
} AlEd[maxn<<2],*p=AlEd;
struct node{
vector<ed*> To,Eto;
int id,nid,color;
int dist1,dist2;
} nd [maxn]; inline void ade(int f,int t){
*p=(ed){nd+f,nd+t,p+1};
nd[f].Eto.pb(p);
nd[f].To.pb(p++);
*p=(ed){nd+t,nd+f,p-1};
nd[t].Eto.pb(p);
nd[t].To.pb(p++);
} struct qry{ int f,t,id; } qrs[maxm]; int nowColor,ans[maxm]; //#define idbg
#ifdef idbg
#define debug(...) {fprintf(stderr,__VA_ARGS__);fflush(stderr);}
// #define assert(...)
inline void tensenx(int&p,int b){
if(b<p) p=b;
}
#define xassert(x,...) if(!(x)){ \
debug(__VA_ARGS__);exit(3); \
}
#define tensen(a,...) { \
int t=__VA_ARGS__; \
xassert(t >= 0,"Tensened with: %d, code:\n" #__VA_ARGS__,t); \
tensenx(a,t); \
}
#define ProgDBG(...) { __VA_ARGS__; }
#else
#define debug(...)
inline void tensen(int&p,int b){
if(b<p) p=b;
}
#define ProgDBG(...)
#endif typedef vector<node*> vn;
typedef vector<qry*> vq;
/// generate bfs functions
#define bfsx(x) inline void bfs##x(node*from){ \
ProgDBG( debug("BFS"#x"\n"); ) \
static node*queue[maxn]; \
int ql=0,qr=1,col=from->color; \
queue[0]=from; \
from->dist##x=0; \
while(ql-qr){ \
node*v=queue[ql++]; \
ProgDBG( \
debug("Vis %d\n",v->id); \
) \
for(int i=0,_=v->Eto.size();i<_;++i){ ed*p=v->Eto[i]; \
if(p->t->color==col && !(~p->t->dist##x)){ \
p->t->dist##x=v->dist##x+1; \
queue[qr++]=p->t; \
}else{ \
ProgDBG( \
if(p->t->color!=col){ \
debug("%d color not match\n",p->t->id); \
}else{ \
debug("%d dist"#x"(%d) mismatch\n",p->t->id,p->t->dist##x); \
} \
) \
} \
} \
} \
} /// bfs1 & bfs2
bfsx(1);
bfsx(2); void div(vn nodeList,vq qryList){
ProgDBG(
debug("Div Nodes: ");
for(int i=0,_=nodeList.size();i<_;++i){
debug("%d ",nodeList[i]->id);
}
debug("\n");
); if(nodeList.size()<=3){
for(int i=0,_=qryList.size();i<_;++i){
tensen(ans[qryList[i]->id],qryList[i]->f!=qryList[i]->t);
}
}else{
int color=nowColor++;
for(int i=0,_=nodeList.size();i<_;++i){
nodeList[i]->color=color;
nodeList[i]->nid =i;
nodeList[i]->dist1=-1;
nodeList[i]->dist2=-1;
}
/// Find edge to cut.
int len=nodeList.size();
int maxlen=len;
ed*cur=NULL;
for(int i=0,_=nodeList.size();i<_;++i){
for(int j=0,_=nodeList[i]->Eto.size();j<_;++j){ ed*p=nodeList[i]->Eto[j];
if(p->t->color==color){
ProgDBG(
debug("Has Edge: %d -> %d\n",p->f->id,p->t->id);
) int fx=p->f->nid,
tx=p->t->nid;
if(fx>tx) std::swap(fx,tx);
int na=fx+len-tx+1;
int nb=tx-fx+1;
na=na>nb?na:nb;
if(na<maxlen) maxlen=na, cur=p;
}
}
}
/// Calculate answer through this edge and divide the queries
bfs1(cur->f);
bfs2(cur->t);
int ef=cur->f->nid;
int et=cur->t->nid; ProgDBG(
debug("Cut edge: (NID) %d %d\n",ef,et);
debug(" (ID) %d %d\n",cur->f->id,cur->t->id);
) if(ef>et) std::swap(ef,et);
vq qryA,qryB;
for(int i=0,_=qryList.size();i<_;++i){
qry*p=qryList[i];
tensen(ans[p->id],nd[p->f].dist1+nd[p->t].dist1);
tensen(ans[p->id],nd[p->f].dist1+nd[p->t].dist2+1);
tensen(ans[p->id],nd[p->f].dist2+nd[p->t].dist1+1);
debug("%d %d %d %d\n",p->f,nd[p->f].dist2,p->t,nd[p->t].dist2);
tensen(ans[p->id],nd[p->f].dist2+nd[p->t].dist2);
int qf=nd[p->f].nid;
int qt=nd[p->t].nid;
if(qf>qt) std::swap(qf,qt);
if(qf==ef && qt==et) continue;
if(qf<=ef){
if(qt>=et || qt<=ef) qryA.pb(p);
}else
if(qf>=et) qryA.pb(p);
if(qf>=ef && qf<=et){
if(qt>=ef && qt<=et) qryB.pb(p);
}
}
/// divide nodes
vn ndA,ndB;
for(int i=0,_=nodeList.size();i<_;++i){
if(i<=ef) ndA.pb(nodeList[i]);
if(i>=et) ndA.pb(nodeList[i]);
if(i>=ef && i<=et) ndB.pb(nodeList[i]);
}
vector<ed*> pat=nodeList[ef]->Eto;
vector<ed*> pbt=nodeList[et]->Eto;
vector<ed*> qat, qbt, xat, xbt;
for(int i=0,_=pat.size();i<_;++i){
if(pat[i]->t->nid<=ef) qat.pb(pat[i]);
if(pat[i]->t->nid>=et) qat.pb(pat[i]);
if(pat[i]->t->nid>=ef && pat[i]->t->nid<=et) qbt.pb(pat[i]);
}
for(int i=0,_=pbt.size();i<_;++i){
if(pbt[i]->t->nid<=ef) xat.pb(pbt[i]);
if(pbt[i]->t->nid>=et) xat.pb(pbt[i]);
if(pbt[i]->t->nid>=ef && pbt[i]->t->nid<=et) xbt.pb(pbt[i]);
}
nodeList[ef]->Eto=qat; nodeList[et]->Eto=xat;
div(ndA,qryA);
nodeList[ef]->Eto=qbt; nodeList[et]->Eto=xbt;
div(ndB,qryB);
}
} int main(){
frp(B,r,in);
frp(B,w,out);
int n; scanf("%d",&n);
for(int i=1;i<=n;++i) ade(i,i%n+1),nd[i].id=i;
for(int i=3;i< n;++i){
int a,b; scanf("%d%d",&a,&b); ade(a,b);
}
int q; scanf("%d",&q);
for(int i=1;i<=q;++i){ scanf("%d%d",&qrs[i].f,&qrs[i].t); qrs[i].id=i; }
vn A; vq B;
for(int i=1;i<=n;++i) A.pb(nd+i);
for(int i=1;i<=q;++i) B.pb(qrs+i);
memset(ans,0x3f,sizeof(ans));
div(A,B);
for(int i=1;i<=q;++i) printf("%d\n",ans[i]);
return 0;
}

C++ 输出调试的一些技巧的更多相关文章

  1. Java常用的输出调试技巧

    --------siwuxie095                 Eclipse 开发中常用的输出调试技巧:     先在左侧的 Package Explorer,右键->New->J ...

  2. VS调试的简单技巧

    学习之路三十二:VS调试的简单技巧   这段时间园子里讲了一些关于VS的快捷键以及一些配置技巧,挺好的,大家一起学习,一起进步. 这段时间重点看了一下关于VS调试技巧方面的书,在此记录一下学习的内容吧 ...

  3. C++ MFC控制台输出调试信息

    1.#include <conio.h> 2.在需要开启控制台窗口的地方调用 AllocConsole();//注意检查返回值 3.在需要输出调试的时候调用_cprintf等函数 如_cp ...

  4. js操作dom---创建一个域来输出调试信息

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  5. 在MFC中,使用控制台Console输出调试信息

    1.在MFC的应用类的InitInstance()函数里添加: AllocConsole(); 有时候需要调整这行代码在InitInstance函数的位置 2.继续添加以下代码 freopen(&qu ...

  6. 使用OutputDebugString输出调试信息

    在编写控制台程序的时候我们经常会使用printf输出调试信息,使我们了解程序的状态,方便调试,但是当编写非控制台程序的时候这种方法就行不通了,那我们应该怎么办?上网查了一些方法,大致就如下几种 使用L ...

  7. shell输出调试信息

    [shell输出调试信息] 1.使用trap命令 trap命令用于捕获指定的信号并执行预定义的命令. 其基本的语法是: trap 'command' signal 其中signal是要捕获的信号,co ...

  8. Delphi中使用Dos窗口输出调试信息

    在项目文件 *.DPR (Project->View Source)  里加上{$APPTYPE   CONSOLE} 然后,在需要输出处加上 Writeln(‘your debug messa ...

  9. 【OT1.0 + TP3.2】开启trace调试、输出调试信息、开启自定义菜单

    1.开启trace调试 A- 后台系统设置 show-page-trace = 1 B-config.php文件.配置 show-page-trace = true 2.输出调试信息 很奇怪,OT竟然 ...

随机推荐

  1. Order Independent Transparency

    http://on-demand.gputechconf.com/gtc/2014/presentations/S4385-order-independent-transparency-opengl. ...

  2. 利用Ramdisk为Firefox 加速

    用Firefox的人可能会羡慕Chrome的速度,但是又不舍得丢弃Firefox.Firefox的加速,可能通过一系列的方法,例如用fasterfox扩 展.但利用虚拟内存盘 Ramdisk ,将将内 ...

  3. Redis安装及主从配置(转)

    一.何为Redis redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有 ...

  4. 使用 Ant 自动生成项目构建版本

    引言 对 于多版本项目,要提供新版本来跟上新功能或缺陷报告增加的速度,并同时仍然保持可接受的质量水平,可能是一项不小的挑战.构建自动化可确保准确性和消除人 为错误的可能性,从而部分地解决此问题.自动化 ...

  5. Eclipse闪退无法打开的解决方法

    使用Eclipse过程中但是有时会出现打不开闪退的情况,这是为什么呢,遇到这种情况怎么解决.东坡小编通过查找资料,发现如下方法可以解决eclipse打不开闪退,具体操作如下: Eclipse打不开闪退 ...

  6. 关于360的META设置,强制使用极速模式

    我的网站,为了使360浏览器打开时默认为极速模式,给用户良好的体验!避免网页由于细节而导致页面布局错乱~ <!DOCTYPE HTML> <html> <head> ...

  7. 未能从程序集“System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”中加载类型“System.ServiceModel.Activation.HttpModule”。

    ********************************* 思路壹(也是网络上铺天盖地的通俗解决方案) 原因: 这是因为先安装了 .NET Framework , 随后启用了 .NET Fra ...

  8. LYDSY模拟赛day3 平均数

    [ 问题描述]有一天, 小 A 得到了一个长度为 n 的序列.他把这个序列的所有连续子序列都列了出来, 并对每一个子序列都求了其平均值, 然后他把这些平均值写在纸上, 并对它们进行排序,最后他报出了第 ...

  9. ie下获取上传文件全路径

    ie下获取上传文件全路径,3.5之后的火狐是没法获取上传文件全路径的 /*获取上传文件路径*/ function getFilePath(obj) { var form = $(this).paren ...

  10. 在PHP中遍历数据库表中的数据

    数据库中的数据: //1.分别将每一行的每一列遍历出来 //mysql_fetch_row()函数在每一次遍历后会将指针向后自动移动一个单位 while($row=mysql_fetch_row($r ...