} int n; void read(){ scanf("%d",& n); REP(i,n)par [i] [0] = par [i] [1] = - 1; int k; scanf("%d"& k); REP(i,k){ int a,b,c;的scanf(QUOT;%d%d%d",&安培;一,和b,和C); - 一个; --b; --c; par [a] [0] = b; par [a] [1] = c; } } void calc(int a,int b){ if(done [a] [b])return; if(a == b){pr [a] [b] .set1();完成[A] [B] = TRUE;返回; } if(dnr [a]< dnr [b])swap(a,b); if(par [a] [0] == - 1)swap(a,b); if(par [a] [0] == - 1){ pr [a] [b] .set0(); } else { calc(par [a] [0],b); calc(par [a] [1],b); pr [a] [b] .dodaj(pr [par [a] [0]] [b],pr [par [a] [1]] [b]); pr [a] [b] .div2(); } pr [ b] [a] = pr [a] [b]; 完成[a] [b] =完成[b] [a] =真; } int main(){ read(); REP(i,n)dnr [i] = - 1; ddd = 0; REP(i,n)dfs( i); REP(a,n)REP(b,n)完成[a] [b] = false; int m; scanf("%d"& m); REP(i,m){ int a,b; scanf("%d%d"& a) ,& b); --a; --b; calc(a,b); pr [a] [b] .wypisz(); } } - 答:因为它弄乱了人们通常阅读文字的顺序。 问:为什么这么糟糕? A:热门发布。 问:usenet和电子邮件中最烦人的是什么? Alf P. Steinbach在留言中写道 < 43 ***************** @ news.individual .net> ... * blackswift:代码来自华沙大学的CEPC代码。他们是ICPC决赛的世界冠军。 / blockquote> 当代码写完时,希特勒仍然掌权吗? <呵呵?> CEPC - 幼稚错误产生代码。 ICPC - (我?刺激:非理性)编码实践竞赛。 < / huh?> 可维护的代码宏是邪恶的,语言扩展是邪恶的,是神秘的名字是邪恶的,全局变量是邪恶的,等等。 你好Alf, 平淡让我眼前一亮流血! 如果我有时间,我可以使用g ++ -save_temps标志编译它,只是为了看看 的真实情况。 : - } [自从我有一个'宏汇编程序''(1980)以后我就反宏了。) 整个代码中使用的''i'变量来自? (?声明/定义?) - Bob R POVrookie " BobR" <再*********** @ worldnet.att.net>在消息中写道 news:wF ******************* @ bgtnsc05-news.ops.worldnet.att.net ... Alf P. Steinbach在留言中写道< 43 ***************** @ news.individual.net> .. 。 * blackswift:代码来自华沙大学的CEPC代码。他们是ICPC决赛的世界冠军。 <呵呵?> CEPC - 幼稚错误产生代码。 ICPC - (我?刺激:无理性编码实践竞赛。< / huh?> 对于可维护的代码宏是邪恶的,语言扩展是邪恶的,含糊不清的名字是邪恶的,全局变量是邪恶的,等等。 你好阿尔夫, 平坦让我的眼睛流血! 让我发痒。 :-) 如果我有时间,我可以使用g ++ -save_temps标志编译它,只是为了看看它到底是什么样的。 : - } [自从我得到一个'宏汇编程序'(1980)以来,我就是反宏的。) heck在哪里''i''变量,用过在整个代码中,来自?(?声明/定义?) 它是在宏FORD,FORD和REP的扩展中创建的 -Mikecode is from Warsaw university''s CEPC code .They are world champion in the ICPC finals.#include <iostream>#include <cstdio>#include <algorithm>using namespace std;#define FOR(i,a,b) for(int i=(a);i<=(b);++i)#define FORD(i,a,b) for(int i=(a);i>=(b);--i)#define REP(i,n) for(int i=0;i<(n);++i)#define VAR(v,x) __typeof(x) v=x#define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i)template<class T>inline int size(const T&a) { return a.size(); }////////const int NDIGS=40;const int BASE = 100000000;const int BASEDIGS = 8;class Num {int a[NDIGS];void popraw() {int p=0;FORD(i,NDIGS-1,0) {a[i]+=p;p=a[i]/BASE;a[i]%=BASE;}}public:void set0() { REP(i,NDIGS) a[i]=0; }void set1() { REP(i,NDIGS) a[i]=0; a[0]=1; }void dodaj(const Num&x,const Num&y) {REP(i,NDIGS) a[i]=x.a[i]+y.a[i];popraw();}void div2() {int p=0;REP(i,NDIGS) {a[i]+=p;p=(a[i]&1)==0?0:BASE;a[i]>>=1;}}/* void dodajIloczyn(const Num&x,const Num&y) {REP(i,NDIGS) REP(j,NDIGS-i)a[i+j] += x.a[i]*y.a[j];popraw();} */void wypisz() {int res[BASEDIGS*(NDIGS-1)+1];int p=BASEDIGS*(NDIGS-1)+1;FORD(i,NDIGS-1,1) {int x=a[i];REP(j,BASEDIGS) { res[--p]=x%10; x/=10; }}res[0]=a[0];int aa=0,bb=(NDIGS-1)*BASEDIGS;while(aa<2 && res[aa]==0) ++aa;while(bb>2 && res[bb]==0) --bb;FOR(i,aa,bb) {putchar(''0''+res[i]);if(i==2 && i<bb) putchar(''.'');}printf("%%\n");}};const int MAXN = 301;int n;int par[MAXN][2];bool done[MAXN][MAXN];Num pr[MAXN][MAXN];int dnr[MAXN];int ddd;void dfs(int x) {if(dnr[x]!=-1) return;if(par[x][0]!=-1) REP(i,2) dfs(par[x][i]);dnr[x]=ddd++;}void read() {scanf("%d",&n);REP(i,n) par[i][0]=par[i][1]=-1;int k; scanf("%d",&k);REP(i,k) {int a,b,c; scanf("%d%d%d",&a,&b,&c); --a; --b; --c;par[a][0]=b;par[a][1]=c;}}void calc(int a,int b) {if(done[a][b]) return;if(a==b) { pr[a][b].set1(); done[a][b]=true; return; }if(dnr[a]<dnr[b]) swap(a,b);if(par[a][0]==-1) swap(a,b);if(par[a][0]==-1) {pr[a][b].set0();}else {calc(par[a][0],b);calc(par[a][1],b);pr[a][b].dodaj(pr[par[a][0]][b],pr[par[a][1]][b]);pr[a][b].div2();}pr[b][a]=pr[a][b];done[a][b]=done[b][a]=true;}int main() {read();REP(i,n) dnr[i]=-1;ddd=0;REP(i,n) dfs(i);REP(a,n) REP(b,n) done[a][b]=false;int m; scanf("%d",&m);REP(i,m) {int a,b;scanf("%d%d",&a,&b);--a; --b;calc(a,b);pr[a][b].wypisz();}} 解决方案 * blackswift: code is from Warsaw university''s CEPC code . They are world champion in the ICPC finals.This style is very ungood for code that is to be maintained.For maintenable code macros are evil, language-extensions are evil,cryptic names are evil, global variables are evil, and so on.But judging the style in a context different than the original isprobably not meaningful.If this is write-only code where the goal is to write the code fastestpossible, any measure that reduces the number of letters typed can behelpful.Of course the programmer then needs to be able to keep it all in thehead, but presumably the programmer was able to do just that: it is,after all, a small program. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define FORD(i,a,b) for(int i=(a);i>=(b);--i) #define REP(i,n) for(int i=0;i<(n);++i) #define VAR(v,x) __typeof(x) v=x #define FOREACH(i,c) for(VAR(i,(c).begin());i!=(c).end();++i) template<class T> inline int size(const T&a) { return a.size(); } //////// const int NDIGS=40; const int BASE = 100000000; const int BASEDIGS = 8; class Num { int a[NDIGS]; void popraw() { int p=0; FORD(i,NDIGS-1,0) { a[i]+=p; p=a[i]/BASE; a[i]%=BASE; } } public: void set0() { REP(i,NDIGS) a[i]=0; } void set1() { REP(i,NDIGS) a[i]=0; a[0]=1; } void dodaj(const Num&x,const Num&y) { REP(i,NDIGS) a[i]=x.a[i]+y.a[i]; popraw(); } void div2() { int p=0; REP(i,NDIGS) { a[i]+=p; p=(a[i]&1)==0?0:BASE; a[i]>>=1; } } /* void dodajIloczyn(const Num&x,const Num&y) { REP(i,NDIGS) REP(j,NDIGS-i) a[i+j] += x.a[i]*y.a[j]; popraw(); } */ void wypisz() { int res[BASEDIGS*(NDIGS-1)+1]; int p=BASEDIGS*(NDIGS-1)+1; FORD(i,NDIGS-1,1) { int x=a[i]; REP(j,BASEDIGS) { res[--p]=x%10; x/=10; } } res[0]=a[0]; int aa=0,bb=(NDIGS-1)*BASEDIGS; while(aa<2 && res[aa]==0) ++aa; while(bb>2 && res[bb]==0) --bb; FOR(i,aa,bb) { putchar(''0''+res[i]); if(i==2 && i<bb) putchar(''.''); } printf("%%\n"); } }; const int MAXN = 301; int n; int par[MAXN][2]; bool done[MAXN][MAXN]; Num pr[MAXN][MAXN]; int dnr[MAXN]; int ddd; void dfs(int x) { if(dnr[x]!=-1) return; if(par[x][0]!=-1) REP(i,2) dfs(par[x][i]); dnr[x]=ddd++; } void read() { scanf("%d",&n); REP(i,n) par[i][0]=par[i][1]=-1; int k; scanf("%d",&k); REP(i,k) { int a,b,c; scanf("%d%d%d",&a,&b,&c); --a; --b; --c; par[a][0]=b; par[a][1]=c; } } void calc(int a,int b) { if(done[a][b]) return; if(a==b) { pr[a][b].set1(); done[a][b]=true; return; } if(dnr[a]<dnr[b]) swap(a,b); if(par[a][0]==-1) swap(a,b); if(par[a][0]==-1) { pr[a][b].set0(); } else { calc(par[a][0],b); calc(par[a][1],b); pr[a][b].dodaj(pr[par[a][0]][b],pr[par[a][1]][b]); pr[a][b].div2(); } pr[b][a]=pr[a][b]; done[a][b]=done[b][a]=true; } int main() { read(); REP(i,n) dnr[i]=-1; ddd=0; REP(i,n) dfs(i); REP(a,n) REP(b,n) done[a][b]=false; int m; scanf("%d",&m); REP(i,m) { int a,b; scanf("%d%d",&a,&b); --a; --b; calc(a,b); pr[a][b].wypisz(); } }--A: Because it messes up the order in which people normally read text.Q: Why is it such a bad thing?A: Top-posting.Q: What is the most annoying thing on usenet and in e-mail?Alf P. Steinbach wrote in message<43*****************@news.individual.net>...* blackswift: code is from Warsaw university''s CEPC code . They are world champion in the ICPC finals.Was Hitler still in power when that code was written?<huh?>CEPC - Childish Error Producing Code.ICPC - ( I ? Irritating : Irrational ) Coding Practices Contest.</huh?> For maintenable code macros are evil, language-extensions are evil,cryptic names are evil, global variables are evil, and so on.Hi Alf,Flat-out makes my eyes bleed!If I get time, I may compile it with the g++ -save_temps flag, just to seewhat it really looks like. :-}[ I am anti-macro ever since I got a ''macro Assembler''(1980).]Where the heck does the ''i'' variable, used throughout the code, come from?(? declaration/definition ?)--Bob RPOVrookie"BobR" <Re***********@worldnet.att.net> wrote in messagenews:wF*******************@bgtnsc05-news.ops.worldnet.att.net... Alf P. Steinbach wrote in message <43*****************@news.individual.net>...* blackswift: code is from Warsaw university''s CEPC code . They are world champion in the ICPC finals. Was Hitler still in power when that code was written? <huh?> CEPC - Childish Error Producing Code. ICPC - ( I ? Irritating : Irrational ) Coding Practices Contest. </huh?>For maintenable code macros are evil, language-extensions are evil,cryptic names are evil, global variables are evil, and so on. Hi Alf, Flat-out makes my eyes bleed!Makes mine itch. :-) If I get time, I may compile it with the g++ -save_temps flag, just to see what it really looks like. :-} [ I am anti-macro ever since I got a ''macro Assembler''(1980).] Where the heck does the ''i'' variable, used throughout the code, come from? (? declaration/definition ?)It''s created in the expansions of macros FOR, FORD, and REP-Mike 这篇关于这种风格好吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-29 00:31