Common BoardThis task can be soved using a linear Frederickson shortest path algo. I thought my algo is all right but got wa3&5. Why? Because I saw this in the statement: rounded to the integer So,I wrote printf("%.0lf",a+0.49999999); But it seemed to be wrong. I checked again and again,finally I found the problem: When you use %x.ylf,where x and y are numbers,the result is automatically rounded. However,when using (int)a,it means FLOOR. So,if you want to write rounded ans,there are 2 ways: printf("%d",(int)(a+0.499999999)); or printf("%.0lf",a); Nice! Now it works, thank you :0 only one JVM definilty couldn't use such low memory. I have isolated the trees at first, then i ran a topsort. I dont understand why i get WA #8 It is not topological sorting task :) Please tell me why this program give WA on test8, thanks! #include <iostream> using namespace std; void main() { int sum=0; char s[1000]; first: while(cin.getline(s,1000)) { for(int i=0;i<strlen(s);i++) { switch(s[i]) { case'a':case'd':case'g':case'j':case'm':case'p':case's':case'v':case'y':case'.':case' ': sum+=1; break; case'b':case'e':case'h':case'k':case'n':case'q':case't':case'w':case'z':case',': sum+=2; break; case'c':case'f':case'i':case'l':case'o':case'r':case'u':case'x':case'!': sum+=3; break; } } } cout<<sum; } dude,that's my problem too,plz tell me if you got the solution. thanx==>cena В двух местах "число не превышающие 35" следует заменить на "число, не превышающее 35". In russian ver.: "Если оно больше некоторого уровня (вам его тоже скажут), то считаем, что объект найден. Тогда вам надо будет выдать сигнал наличия объекта и глубину его нахождения" In english ver.: "If a maximal number is equal to or greater than a certain level, which you'll be given, then you report that you have found an object and give us its location." Compare: "больше" and "equal to or greater" Please, fixed this. =) I can't understand what's wrang? I just build BST and make reverse post order.. Maybe there are some troubles with input? Please help me. [I'll delete code after receiving some feedback] [Code deleted] Edited by author 29.11.2012 21:04 problem was in wrang input: input values could be in different lines... i've changed int[] arr = parseInt(Console.ReadLine().Trim().Split(' ')); to int[] arr = parseInt(sReader.ReadToEnd().Split(new char[] {' ', '\t', '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries)); and get AC;) Edited by author 29.11.2012 21:06 Если взглянуть на Рейтинг решения задач, и пройтись по столбику "Выделено памяти", то у ребят из ТОПа выделено 18, 38, 74, 78кб памяти. Но как, как, как возможен такой маленький расход памяти, там же реально меньше 300 кб не добиться, ну никак! В чем же тут загадка??? там нет таких Edited by author 29.11.2012 19:01 Should it be geometry or physics ??? I've found that test #1 is the same as sample. I've special-cased it in my program to output exactly what is in the sample output, but I still get WA1. Why? Looks like it depends on language: C and Java program output exactly the same, but C program passes the test, and Java program doesn't. Edited by author 03.08.2011 00:41 I also encountered this problem; exactly the same symptoms. #include<stdio.h> #include<conio.h> int main() { int a, sum = 0; scanf("%d",&a); if( a > 0 ) { for ( int i = -1; i <= a; i++) sum += i; } else { for (int i = 1; i <= -a; i++) sum += i; sum = 1 - sum; } printf("summa ravna %d",sum); getch(); } first: printf("summa ravna %d",sum); use just: printf("%d",sum); second: don't use: getch(); third: if A>0 sum from 1, not from -1 #include <stdio.h> #include <math.h> long long int k,n; void reverce (void); int main(void) { reverce(); return 0; } void reverce (void) { long long int a; while(scanf("%lld", &a)) { k++; n++; reverce(); } if (k == n) { n--; return; } printf("%.4lf\n", (double)sqrt(a)); } Edited by author 29.11.2012 01:43 I use dijkstra algo, what's wrong? code #include <cstdio> #include <vector> #include <map> #include <set> using namespace std; const long long INF=100000000; typedef unsigned long long ULL; typedef pair<long long,long long> pii; typedef vector<vector<long long> > VVI; typedef vector<long long> vi; typedef map<long long,vi> MIV; MIV network; VVI G; long long n=1,n_int; void init_vert(){ for (long long i=0;i<=n;++i){ vector< long long > temp; G.push_back(temp); } for (MIV::iterator it=network.begin();it!=network.end();++it){ for(vi::iterator vit=it->second.begin();vit!=it->second.end();++vit){ for(vi::iterator vit2=it->second.begin();vit2!=it->second.end();++vit2){ G[*vit].push_back(*vit2); } } } } long long read_network(){ long long res=0; long long mask=0; long r1,r2,r3,r4; long m1,m2,m3,m4; scanf("%ld.%ld.%ld.%ld",&r1,&r2,&r3,&r4); scanf("%ld.%ld.%ld.%ld",&m1,&m2,&m3,&m4); res+=r1&m1;res<<8; res+=r2&m2;res<<8; res+=r3&m3;res<<8; res+=r4&m4; return res; } vector<long long> dist,parent; void dejkstra(long long s){ dist.assign(n+1,INF); parent.assign(n+1,INF); dist[s]=0; set<pair<long long,long long> > q; q.insert(make_pair(dist[s],s)); while (!q.empty()){ long long v=q.begin()->second; q.erase(q.begin()); for (size_t j=0;j<G[v].size();++j){ long long to=G[v][j]; if (dist[v]+1<dist[to]){ q.erase(make_pair(dist[to],to)); dist[to]=dist[v]+1; parent[to]=v; q.insert(make_pair(dist[to],to)); } } } } int main(){ //freopen("in","r",stdin); scanf("%lld",&n); long long n_n_m=0; for (size_t i=0;i<n;++i){ scanf("%lld",&n_int); for (size_t j=0;j<n_int;++j){ n_n_m=read_network(); network[n_n_m].push_back(i+1); } } init_vert(); long long _beg,_end; scanf("%lld%lld",&_beg,&_end); dejkstra(_beg); if (dist[_end]==INF){ printf("No\n"); return 0; } else{ printf("Yes\n"); long long p=_end; vector<long long>res; printf("%lld ",_beg); while(p!=_beg){ // printf(">>>%d\n",p); res.push_back(p); p=parent[p]; } for (vi::reverse_iterator it=res.rbegin();it!=res.rend();++it){ printf("%lld ",*it); } printf("\n"); } return 0; } #include <cstdio> #include <vector> #include <map> #include <set> using namespace std; const long long INF=10000; typedef unsigned long long ULL; typedef unsigned long UL; typedef pair<int,int> pii; typedef vector<int> vi; int n=0,n_int=0; vector<pair<int,int> > G; map<UL,vi > network; void init_vert(){ for (map<UL,vi >::iterator it=network.begin();it!=network.end();++it){ for(vi::iterator vit=it->second.begin();vit!=it->second.end();++vit){ for(vi::iterator vit2=it->second.begin();vit2!=it->second.end();++vit2){ if ( ( *vit ) != ( *vit2 ) ){ G.push_back(make_pair(*vit,*vit2)); } } }
} } UL read_network(){ UL res=0; long r1,r2,r3,r4; long m1,m2,m3,m4; scanf("%ld.%ld.%ld.%ld",&r1,&r2,&r3,&r4); scanf("%ld.%ld.%ld.%ld",&m1,&m2,&m3,&m4); res+=r1&m1;res<<4; res+=r2&m2;res<<4; res+=r3&m3;res<<4; res+=r4&m4; return res; } vector<long> dist; vector<int> parent; void FB(int start,int end){ dist.assign(n,INF); parent.assign(n,-1); dist[start]=0; for (size_t i=0;i<n;++i){ for (vector<pair<int,int> >::iterator it=G.begin();it!=G.end();++it){ if (dist[it->first]<INF){ if(dist[it->second]>dist[it->first]+1){
dist[it->second]=dist[it->first]+1; parent[it->second]=it->first; } } } } }
int main(){ freopen("in","r",stdin); scanf("%d",&n); UL n_n_m=0;
for (size_t i=0;i<n;++i){ scanf("%d",&n_int); for (size_t j=0;j<n_int;++j){ n_n_m=read_network(); network[n_n_m].push_back(i); } } init_vert(); int _beg,_end;
scanf("%d%d",&_beg,&_end);
FB(_beg-1,_end-1);
if (parent[_end-1]==-1){ printf("No\n"); return 0; } else{ printf("Yes\n"); int p=_end-1; vector<int> res; while(p!=_beg-1){ res.push_back(p); p=parent[p]; } printf("%d ",_beg); for (vi::reverse_iterator it=res.rbegin();it!=res.rend();++it){ printf("%d ",(*it)+1); } printf("\n"); } return 0; } res<<4 => res<<=4 + AC) hi Lex why res<<=4 hi Lex why res<<=4 a<<=8 <==> a = a<<8 Edited by author 28.11.2012 19:53var a,b,n,k:integer; begin readln(n,k); a:=n div 2; if k>a then b:=n-k else if (k=a) or (k=a+1) then b:=0 else b:=a-k; writeln(b) end. Right... I guess this problem was put in here for comic relief. :) For crying out loud, the author didn't even bother to increase the limits so as to make this a 'bignum' problem... :P This is "Осеннее первенство школьников 2003". Now you understand why it is so easy? And yet, this problem has a higher site difficulty than Ural Steaks, which is a much more sophisticated problem than this one. The difficulty of a problem is not necessarily related to how much code it takes to solve it, the point of problem solving is to map scenarios to programs that solve them. It is the proper understanding of the problem where a lot of the difficulty (and most of the importance!) lies. Me too. Does anyone know what's so special about #5? Edited by author 15.07.2008 10:16 I had this problem. You have to write #pragma comment(linker, "/STACK:1000000000") in your program, if you use C++ Indeed, I had the same problem but after I put this ( #pragma comment(linker, "/STACK:1000000000") ) it works. Anyway, what does this do? Why does my program works if I write this? У меня программа получила AC, хотя на тест 1999 выдавала ответ 1991... мне кажется, что это не совсем верно... New tests were added. Thank you. Зачем добавлять новые тесты, если по уже существующим нельзя пройти на верной программе? Edited by author 27.11.2012 23:29 Edited by author 27.11.2012 23:29 Why do you think that your program is right? |
|