Common BoardCould someone tell me how to input double fast in C++ ? scanf is not fast enough Edited by author 25.11.2014 08:55 10+1 + 5+1 + 2 = 19. And there is no other way 10+1+5+1=17 So what happens with the person with time 2? How is that possible? M stands for mine detector. 1 2 5 10 M - empty 2 5 - 1 10 M (+10) 1 2 5 M - 10 (+1) 2 - 1 5 10 M (+5) 1 2 M - 5 10 (+1) empty - 1 2 5 10 (+2) 10 + 1 + 5 + 1 + 2 = 19 Which is 19, not 17. That's why we are asking how can it be 17? 1 2 5 10 | --- = 0 5 10 | 1 2 = 2 1 5 10 | 2 = 3 1 | 5 10 2 = 13 1 2 | 5 10 = 15 --- | 1 2 5 10 = 17 You can use DFS find the tips as this. [code deleted] Edited by moderator 19.11.2019 22:57 Hi, I had wrong answer on test 9. Then I found an error and got the problem accepted. My test may be useful: 1000 1000 1 1 2 1 1 2 50 50 1 10 10 11 10 10 11 69.392 0.343 sec. Just to let you know. ;) Heh, 0.35 sec... Mine is O(N^4) and 0.078 #include <stdio.h> #include <math.h> #include <iostream> #include <stdlib.h> using namespace std; int main() { long int range, total = 0; cin >> range; if ( range <= 0 && abs(range) < 10000 ) { for ( int x = 1; x >= range; --x ) total += x; cout << total << endl; } else if ( range > 0 && abs(range) < 10000 ) { for ( int x = 1; x <= range; ++x ) total += x; cout << total << endl; } return 0; } Edited by author 22.11.2014 20:22 #include <math.h> #include <iostream> using namespace std; int main() { double *a = new double[131073]; double temp; int i = 0; while (cin >> temp) a[i++] = sqrt(temp); while (i > 0) { printf("%.4f\n", a[--i]); } delete[] a; return 0; } What could test 43 be? If the spell distroys 0 coins, is the minimum amount of spells also 0? Or is it 1? The amount of spells has to be 0 too. Problem #43 is the 0 0 case, but I didn't set my counters to 0 0 the right way. Not very smart. This case helped me 10 18 2 2 2 2 2 2 2 2 2 2 Thank you. This test case really helped me~ Can there be identical threads in the test? Like: 4 4 1 2 1 2 2 3 3 4 3 1 2 3 And if they can occur is the answer 2 2 3 or 1 2 3? My program gives: 1 2 3 I got AC. It is a web. The web is not a multigraph. All edges will be unique. I have got AC, but I have found test for which my AC program gives wrong answer. I sent it to timus_support@acm.timus.ru. #include <iostream> #include <cstdio> using namespace std; int main() { int a, b, c[10000], n, p, sum = 0, i, k, s, m; scanf("%i %i", &a, &b); for(i = 1;i <= b ; i++) { scanf("%i", &c[i]); sum += c[i - 1]; } k = sum - a * (b - 1); if(k <= 0) { m = c[b] - a; if(m <= 0) printf("0\n"); else printf("%i\n", m); } else { n = (k + c [b]) - a; if(n <= 0) printf("0\n"); else printf("%i\n", n); } } Edited by author 20.11.2014 20:03 n = 8, k = 3 one computer already has got prog installed, so you start copying from that one. you copied to any one (to exactly one as problem requires), 1 hour passed, k = 2 (2 cables left). you copied to next(any) one, 2 hours passed, k = 1 (and 1 cable left), copied to next - 3 hours passed and no cables left !! at the moment there are 4 computers remaining without programm, so as i see its impossible to copy to all computers, becuase no cables left ... how the hell output is 4 ?? and how you use them 3 cables to copy to all computers ... Whats wroung in this ??? help me please, thanks ! #include <iostream> #include <algorithm> using namespace std; int main() { int n, a; cin >> n >> a; if (n == 1) cout << 0 << endl; else { int S = n - 1; //int S = n; for (int i = 1; i <= n; i++) { S = S - min(a, i); if (S <= 0) { cout << i << endl; break; } } } } can anybody give me some tests? I've seen few people got AC in 0.015 seconds, but how? I used binary search and each iteration's left border started from the last found number, but not from the beginning of array and got 0.031 seconds. binary search gives n*log^2(n) and its possible to solve this in 3*n if you walk the array with least number on each step and wait until all 3 pointed are same to increase count; I have 0.031 too but i`m sure it is possible to optimize my code (e.g. i`ve placed too many checkers if the array is fully passed) int main() { int ma=0,mb=0,mc=0,an,bn,cn,a[4000],b[4000],c[4000],sum=0; scanf("%d",&an); for(int i=0;i<an;++i) scanf("%d",&a[i]); scanf("%d",&bn); for(int i=0;i<bn;++i) scanf("%d",&b[i]); scanf("%d",&cn); for(int i=0;i<cn;++i) scanf("%d",&c[i]); do { while ((a[ma]==b[mb])&&(b[mb]==c[mc])) { ++sum; ++ma; ++mb; ++mc; if((ma>=an)||(mb>=bn)||(mc>=cn)) break; } if((ma>=an)||(mb>=bn)||(mc>=cn)) break; if(a[ma]==min(min(b[mb],c[mc]),a[ma])) ++ma; else if(b[mb]==min(min(b[mb],c[mc]),a[ma])) ++mb; else if(c[mc]==min(min(b[mb],c[mc]),a[ma])) ++mc; if((ma>=an)||(mb>=bn)||(mc>=cn)) break; } while(1); printf("%d", sum); return 0; } You use Python. There is many useful functions))) My program took only 4 lines))) var a:integer; b:integer; va:integer; vb:integer; ea:integer; eb:integer; ra:integer; rb:integer; boxa:integer; boxb:integer; begin readln(a,b); readln(va,vb);
boxb:=b-(va-a); rb:=b-boxb; readln(ea,eb); boxa:=va-(eb-vb);
writeln(a-boxa,' ',b-boxb);
end. /* My program got WA on test 11!!! What's wrong with my code? Anyone can help me!!! */ #include <map> #include <set> #include <ctime> #include <cmath> #include <queue> #include <stack> #include <cstdio> #include <vector> #include <string> #include <cstdlib> #include <cstring> #include <utility> #include <iostream> #include <algorithm> #define FI first #define SE second #define LSON(x) (x<<1) #define RSON(x) ((x<<1)|1) #define Benefit(x,y) x=max(x,y) #define CS const static #define SORT_CMP(s,l,r,cmp) sort(s+(l),s+(r)+1,cmp) #define SORT(s,l,r) sort(s+(l),s+(r)+1) #define MP(x,y) make_pair(x,y) #define Randomize srand( (unsigned int) time ( NULL ) ) #define INOUT(x,y) freopen(x,"r",stdin),freopen(y,"w",stdout) using namespace std; typedef char name[20]; CS int MaxN = 100010 ; struct word { name x; int val,len; word() {x[0] = 0; val = 0;} }; struct Trie { Trie * next[26]; word * ans[10]; Trie() { for(int i=0;i<26;i++) next[i] = NULL ; for(int i=0;i<10;i++) ans[i] = NULL ; } } * Tree; word p[MaxN]; name ask; int n,m,asklen; void Insert(Trie * x,int _y,int pos) { int i; word & y = p[_y]; for(i=0;i<10;i++) if((x->ans[i]==NULL)||(x->ans[i]->val<y.val)) break; if(i<10) { for(int j=9;j>i;j--) x -> ans[j] = x->ans[j-1]; x -> ans[i] = p + _y; } if(pos!=y.len) { int u = y.x[pos] - 'a'; if(!x->next[u]) x -> next[u] = new Trie ; Insert(x->next[u],_y,pos+1); } } void Init() { scanf("%d\n",&n); Tree = new Trie ; for(int i=1;i<=n;i++) { scanf("%s %d\n",p[i].x,&p[i].val); p[i].len=strlen(p[i].x); Insert(Tree,i,0); } } void Query(Trie * x,int pos) { if(pos == asklen) { for(int i=0;i<10;i++) if(x->ans[i]) printf("%s\n",x->ans[i]->x); else break; return ; } int u = ask[pos] - 'a'; if(x->next[u]) Query(x->next[u],pos+1); } void Solve() { scanf("%d\n",&m); while(m--) { scanf("%s\n",ask); asklen = strlen(ask) ; Query(Tree,0); if(m) printf("\n"); } } int main() { Init(); Solve(); return 0; } Edited by author 31.05.2012 14:40 you are an idiot. why so many inclusions? and your code is delirium. ...wrote Nikolay, 43 solved problems and 6000+-th place, to blablabla, 280 solved problems and place within top 1000. P.S. And the code style is not great, but quite okay. Edited by author 19.11.2014 12:32 Some hint: For n = 4 1 : (1,2), (1,3), (1,4); 2 : (2,1), (2,3); 3 : (3,1), (3,2); 4 : (4,1); 1st have 3 friends, 2nd have 2 friends, 3d have 2 friends, 4fth have 1 friend, so ans is 4 1 2 1 3 1 4 2 3 |
|