Общий форумThis problem is not difficult. A lot of people got long sequences of WA#22 (as well as I did) because of one very stupid mistake. I hope this test will help to understand this mistake: 10 10 20 10 100 1 2012 10000 1 30 60 Answer: 15000.0000000 Thanks for the test. I get a different answer (and have WA22) -- 14000. To get your answer from my calculations you're either stopping the cart in the tunnel (which should never be necessary I think) or you're getting a different value for the time when the fire passes the end of the tunnel. I'm not sure where my mistake is. The cart clearly fully enters the tunnel at time 4, and the back of the fire passes the end of the tunnel at time 9 (the fire does not meet the cart before it fully enters the tunnel). 9-4=5. Covering 20 m over 5 seconds with initial velocity 10 requires deceleration of a = 2.4, which is 1.4 more than 1, thus 14000. I'm assuming the front of the cart can't enter the tunnel into the fire... What's wrong with my reasoning? Edited by author 01.11.2012 12:30 With deceleration 2.4 after 5 seconds in the tunnel a velocity of the cart will be equal 10 - 2.4*5 = -2. Oops :) Haha! That's funny. I just used "s = v * t - 1/2 a * t^2" but forgot to check whether it involved "backing up" :). Sorry to Soren and Alba for barbecuing you before backing you up into the safety of the tunnel! I'm sure they'll forgive you. You are not the first who does that ;) It's very funny that this fact didn't allow to solve the problem anybody who tried to do it during the contest. Edited by author 02.11.2012 12:14 At long last, AC. Lots of little details to pay attention to in this one! sort and DP is ok can you explain DP parameters? just use <map> Edited by author 07.11.2012 15:05 Input: 7 2 3 0 3 1 0 1 2 4 5 0 3 0 3 0 7 0 6 0 Output: 4 1 4 5 6 Is it true? Please Give me some tests. Edited by author 03.11.2009 15:17 Edited by author 03.11.2009 15:18 I think your answer is true. Try it: In 4 2 0 1 4 0 4 0 2 3 0 Out 2 1 3 or 2 4
Edited by author 06.11.2009 14:49 #include <iostream> #include <string> using namespace std; int main() { char s[30001]; int a; cin >> a; for(int i=0; i<a; i++) cin >> s[i]; int res=0; bool ok=false; while(!ok) { ok=true; for(int i=0; i<a-1; i++) { if(s[i]=='>' && s[i+1]=='<') { s[i]='<'; s[i+1]='>'; res++; ok=false; i++; }
} //cout << s << ' ' << ok << endl; } cout << res << endl; return 0; } I used very similar code and got AC (though there is a better solution if I recall correctly). What I did is: - Use stdio instead of iostream: it's faster - If you have <<< at left end or >>> at right and, you can ignore those - they will never change again. Thus, you can keep treack of the left and right endings, and only parse those, instead of going from 0 to n every time. AC 0.625 #include <iostream> using namespace std; int main() { char x[30005],l='<',r='>',p; int n,i,s=0,k=1; cin>>n; for(i=0; i<n; i++) cin>>x[i]; while(k!=0) { k=0; for(i=0; i<n; i++) if( x[i]==r && x[i+1]==l) { swap(x[i],x[i+1]); s++; k++;} } cout<<s; return 0; } i don't know how to minimize my prog I used very similar code and got AC (though there is a better solution if I recall correctly). What I did is: - Use stdio instead of iostream: it's faster - If you have <<< at left end or >>> at right and, you can ignore those - they will never change again. Thus, you can keep treack of the left and right endings, and only parse those, instead of going from 0 to n every time. AC 0.625 In The documentation that the type of string is not limited to 255 characters. but the program does not pass the second test. Q: Amount of characters is limited or not? or how to make a string of unlimited? Amandosov sqrt [1] 7 ноя 2012 03:02 please take me the alternative sqrt, without library Could you please explain where this formula comes sqrt (8 * N-7) Edited by author 05.03.2012 01:14 Edited by author 05.03.2012 01:17 Извините, что по-русски. Формула немного другая. Единицы стоят на местах, выражаемых формулой Sn = n*(n+1)/2 + 1, где nэN и n>0. Эта формула получена из соображений арифметической прогрессии. Из этой формулы можно получить, что n = sqrt(2*Sn-1.75) - 0.5 или n = (sqrt(8*Sn-7)-1)/2. Если nэN и n>0, то Sn существует, и на месте Sn стоит единица, иначе - ноль. [code deleted] Edited by moderator 20.11.2019 00:12 I have the same problem for example a write: 5 5 5 5 5 5 my program gives me 9 is it true? Edited by author 06.11.2012 21:15 Edited by author 06.11.2012 21:15 Yes, it's true. and if I write: 4 4 4 4 4 I get 9 too and if I write 5 3 7 6 6 4 I get 9 too i solved problem. i changed from real to word and all OK wht do u mean by real to word nd did ur ques get accept? If you use strictfp flag time will be smaller. For my solution this flag has changed time from 0,109 to 0,093 :) this is my code and its wrking fine on my pc import java.io.*; import java.util.Scanner; public class Democracy { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub
Scanner sc = new Scanner (System.in); System.out.println("enter no of groups"); int n = sc.nextInt();
System.out.println("enter group members"); //String s = sc.next(); //String[] num = s.split(","); String[] num = sc.next().split(",");
int[] num1 = new int[num.length]; int x =0; for(String a: num){ num1[x] = Integer.parseInt(a); //System.out.println(a); x++; }
int len = n/2+1; int[] min = new int[len];
for(int i = 0; i <len; i++ ){ min[i] = num1[i]; for(int j= i+1; j<num1.length; j++ ){ if(min[i] > num1[j]){ min[i] = num1[j]; } } }
int vote = 0; for(int i =0; i<len; i++){ vote = vote+ min[i]/2+1; }
System.out.println(vote);
} } package practice; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Sum {
public static void main(String[] args) { // TODO Auto-generated method stub //Scanner sc = new Scanner (System.in); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int x = 0; int sum = 0; try { x = (int)br.read(); System.out.println("x" +x); if(x >0){ for(int i =1; i <= x ;i++){ sum = sum +i; } } else { for(int i =x; i <=1 ;i++){ sum = sum +i; } }
} catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
System.out.println(sum); } } var k,n,i,sum,s:integer; begin readln(k,n); sum:=0; for i:=1 to n do begin readln(s); sum:=sum+s-k; if sum<0 then sum:=0; end; //sum:=sum+s-k; //if sum<0 then sum:=0; writeln(sum); readln; end. whot wrong? Edited by author 06.11.2012 01:22 var k,n,i,sum,s:integer; begin readln(k,n); sum:=0; for i:=1 to n do begin read(s); // here must be read. not readln; sum:=sum+s-k; if sum<0 then sum:=0; end; //sum:=sum+s-k; //if sum<0 then sum:=0; writeln(sum); end. whot wrong? Edited by author 05.11.2012 17:17 Edited by author 05.11.2012 17:17 If you have WA24 then swap(Li, Hi), and if you have WA30 use aspect ratio in a similar triangle)) #include <iostream> int main() { int n,k,a; std::cin>>n>>k; if ((2*n)%k==0) a=(2*n-(2*n)%k)/k; else a=(2*n-(2*n)%k)/k+1; std::cout<<a; return 0; } wrong answer po4emu ne pravilno, ved algoritm verni? Edited by author 25.10.2012 22:40 Edited by author 25.10.2012 22:40 if ((n%k)*2<=k) {answer=3;} Any hint for solving this problem? number of possible operations is only 1m > number of possible operations is only 1m Hah! Somehow reading this here (even though it's clear in the problem statement) made me see the way...thanks. memcpy (for c++) and million.., and not any more ;p why getche is undefined for compiler.in 'dev c 'i used it and is define program: #include <stdio.h> #include <stdlib.h> int main(int argc, char *argv[]) { int i,j,k,s,b,n; char a,c[99][8][8]; scanf("%d",&n); for(k=0;k<n;k++){ a=getche(); scanf("%d",&b); c[k][(int)a-96][b]='n'; }
for(k=0;k<n;k++){ s=0; for(i=1;i<=8;i++) for(j=1;j<=8;j++) {
if(c[k][i][j]=='n'){ if(i+2<=8&&j+1<=8) s++; if(i+2<=8&&j-1>=1) s++; if(i-1>=1&&j+2<=8) s++; if(i-1>=1&&j-2>=1) s++; if(i-2>=1&&j-1>=1) s++; if(i-2>=1&&j+1<=8) s++; if(i+1<=8&&j-2>=1) s++; if(i+1<=8&&j+2<=8) s++; } } printf("\n%d",s); }
system("PAUSE"); return 0; } because getch() and not getche() |
|