code 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();
}
} 17 1695
* 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 is
probably not meaningful.
If this is write-only code where the goal is to write the code fastest
possible, any measure that reduces the number of letters typed can be
helpful.
Of course the programmer then needs to be able to keep it all in the
head, 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 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 ?)
--
Bob R
POVrookie
"BobR" <Re***********@worldnet.att.net> wrote in message
news: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
BobR wrote: 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?
I think you just ended this thread pre-maturely... /david
Mike Wahler wrote in message "BobR" wrote in message [ 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
Hi Mike,
Ah, I see now, it's only used in the bodies after the macro(s). Thanks Mike.
Also noticed that 'FOR' is only used once. That seems like bad programming
practice to me (aside from using macros (like those) to begin with <G>). No
gain, adds clutter!
--
Bob R
POVrookie da********@warpmail.net wrote in message BobR wrote: >* 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?
I think you just ended this thread pre-maturely... /david
It was NOT a statement, it was a question. And the connection was 'ugly
code', 'ugly war'.
[ The code IMHO looked like something the 'SS' would force upon the world. ].
Sorry you took offense.
--
Bob R
POVrookie
No, I didn't take offence. I was referring to Godwin's Law:
http://en.wikipedia.org/wiki/Godwin's_law
:-) /david
No, I didn't take offence. I was referring to Godwin's Law:
http://en.wikipedia.org/wiki/Godwin's_law
:-) /david da********@warpmail.net wrote in message
<11*********************@g43g2000cwa.googlegroups. com>... No, I didn't take offence. I was referring to Godwin's Law: http://en.wikipedia.org/wiki/Godwin's_law
:-) /david
Interesting.
"Morgan's corollary to Godwin's Law
As soon as such a comparison occurs, someone will start a Nazi-discussion
thread on alt.censorship."
I don't subscribe to alt.censorship, so, would you be so kind as to keep me
informed? <G>
If I had used Nixon in reference to the time period, would I have still
invoked the wrath of Godwin? Does asking that question invoke Godwin's law
again? What questions are we allowed to ask?
Thanks for the link, glad your not mad.
OOOoohh NNOOooooo!
"Guy's corollary
If a Usenet discussion mentions Godwin's law as a conterrebuttal to a mention
of Hitler/Nazis, then the probability of Godwin's law being disputed is equal
to 1.
"
So, if we code:
while( Is_Godwins_law ){
}
....we're instantly in an endless loop?
BTW - "offence" is spelled "offense", I had looked it up. :-}
--
Bob R
POVrookie
BobR wrote:
[snip] BTW - "offence" is spelled "offense", I had looked it up. :-}
Well, the difference between 'c' and 's' is one bit, so it's about the
same. /david
BobR wrote: BTW - "offence" is spelled "offense", I had looked it up. :-}
Ah... the US and the UK. Two countries separated by a common language.
"BobR" <Re***********@worldnet.att.net> wrote in message
news:Wb*******************@bgtnsc05-news.ops.worldnet.att.net... BTW - "offence" is spelled "offense", I had looked it up. :-}
Both are 'correct', which spelling is used usually depends upon
which side of the pond you're on.
-Mike
"BobR" <Re***********@worldnet.att.net> wrote in message
news:CC*******************@bgtnsc05-news.ops.worldnet.att.net... Mike Wahler wrote in message "BobR" wrote in message [ 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
Hi Mike,
Ah, I see now, it's only used in the bodies after the macro(s). Thanks Mike.
Also noticed that 'FOR' is only used once. That seems like bad programming practice to me (aside from using macros (like those) to begin with <G>). No gain, adds clutter!
--
Not to mention the problem of attempting to nest those loops. What is "i"
referring to then???
for (int i = ...
for (int i = ...
a[i] = ...
If it's too much trouble to type in your own loop control statements, then
hire someone else to do it for you! :-)
-Howard
Mike Wahler wrote in message ... "BobR" <Re***********@worldnet.att.net> wrote in message news:Wb*******************@bgtnsc05-news.ops.worldnet.att.net... BTW - "offence" is spelled "offense", I had looked it up. :-}
Both are 'correct', which spelling is used usually depends upon which side of the pond you're on.
-Mike
Oh great! So now we have to write:
"offen( cp==437 ? s : c )e" // <G> [1]
Thanks for the heads-up, Mike.
My apology to david. Next time don't hide yer Englich accent, eh. :-}
[1] - and that only covers the old dos/window$ codepage (?). Is that covered
in the i18n specs?
--
Bob R
POVrookie
> #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)
I really appreciate this style!
Elcaro Nosille <El************@xxx.invalid> wrote: #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)
I really appreciate this style!
It reminds me of
#define BEGIN {
#define END }
--
Marcus Kwok This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: wired |
last post by:
Hi,
I've just taught myself C++, so I haven't learnt much about style or
the like from any single source, and I'm quite styleless as a result.
But at the same time, I really want nice code and I...
|
by: Geoff Cox |
last post by:
Hello,
I publish some web pages using large fonts and would like to give the
user the opportunity to print the pages using a smaller font.
I believe that this is possible using different style...
|
by: Cheng Mo |
last post by:
Recently I happens to read some sourcecode which has different style
from my previous experience.
In this style, all functions return a RETURN_TYPE_T which is defined as
typedef unsigned int...
|
by: TJ Walls |
last post by:
Hello All,
I am fairly new to html authoring and have run into a strange problem.
I have a simple GIF file that is a black horizontal line. As a test
start I am trying to display it twice with...
|
by: Christopher Benson-Manica |
last post by:
How about your if/else if/else constructs? Being nitpicky like any
good C programmer, I'm in the process of transforming code written
like
if( cond ) {
...
} else
if( some_other_cond ) {...
|
by: Natt Serrasalmus |
last post by:
After years of operating without any coding standards whatsoever, the
company that I recently started working for has decided that it might be a
good idea to have some. I'm involved in this...
|
by: jamilur_rahman |
last post by:
What is the BIG difference between checking the "if(expression)" in A
and B ? I'm used to with style A, "if(0==a)", but my peer reviewer
likes style B, how can I defend myself to stay with style A...
|
by: looping |
last post by:
For Python developers around.
>From Python 2.5 doc:
The list of base classes in a class definition can now be empty. As an
example, this is now legal:
class C():
pass
nice but why this...
|
by: Angel Tsankov |
last post by:
Can someone recommend a good source of C/C++ coding style.
Specifically, I am interested in commenting style and in
particular how to indent comments and the commented code, rather
than when to...
|
by: Astley Le Jasper |
last post by:
I'm still learning python and would like to know what's a good way of
organizing code.
I am writing some scripts to scrape a number of different website that
hold similar information and then...
|
by: Rina0 |
last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
|
by: linyimin |
last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
|
by: kcodez |
last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
|
by: Taofi |
last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same
This are my field names
ID, Budgeted, Actual, Status and Differences
...
|
by: DJRhino1175 |
last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this -
If...
|
by: Rina0 |
last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
|
by: DJRhino |
last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer)
If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _
310030356 Or 310030359 Or 310030362 Or...
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: DJRhino |
last post by:
Was curious if anyone else was having this same issue or not....
I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
| |