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).b egin());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:BAS E;
a[i]>>=1;
}
}
/* void dodajIloczyn(co nst 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*(NDI GS-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 1744
* 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).b egin());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:BAS E; a[i]>>=1; } } /* void dodajIloczyn(co nst 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*(NDI GS-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.indi vidual.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.ne t> wrote in message
news:wF******** ***********@bgt nsc05-news.ops.worldn et.att.net... Alf P. Steinbach wrote in message <43************ *****@news.indi vidual.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.indi vidual.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********@warp mail.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.or g/wiki/Godwin's_law
:-) /david
No, I didn't take offence. I was referring to Godwin's Law:
http://en.wikipedia.or g/wiki/Godwin's_law
:-) /david da********@warp mail.net wrote in message
<11************ *********@g43g2 000cwa.googlegr oups.com>... No, I didn't take offence. I was referring to Godwin's Law: http://en.wikipedia.or g/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 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 go to great
lengths to restructure my code just to look concise and make it more
manageable.
When I say this, I'm also referring to the way I write my functions.
It seems to me sometimes that I shouldn't have many void functions
accepting...
|
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 sheets? I am not
clear how the user would select the different .css files?
Seems to be easier than having duplicate html files ...
|
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 RETURN_TYPE_T;
and the return value can only be enum value
enum
{
SUCCESS = 0,
FAILURE = 1,
|
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 the left edge of the second
line aligned with the right edge of the first.
I have set the width of the first line to be 100 pixels with an
absolute position left offset 0. I would think that the correct left
offset of the second line should then...
|
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 ) {
...
} else
| |
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 initiative.
Typically I find that coding standards are written by some guy in the
company who has a way of coding that he likes and then tries to force
everybody else to write code the way he likes it, not for any rational
reason, but simply for the...
|
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 ?
style A:
....
....
int a = 1;
if(0==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 syntax return old-style class, same as "class C:",
and not the new style "class C(object):" ?
|
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 use comments. Thanks in advance!
--
http://www.gotw.ca/resources/clcm.htm for info about ]
|
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 collating it all together. Obviously
each site needs to be handled differently, but once the information is
collected then more generic functions can be used.
Is it best to have it all in one script or split it into per site
scripts that can then...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |