Общий форум#include <iostream> using namespace std; int main(){
int a = 0; int b = 1; int c = 0; int k = 0;
cin >> a;
if(a > b){ k = 1;
for(; b <= a; b = b + k){
c += b;
}
}
else if(a < b){
k = -1;
for(; b >= a; b = b + k){
c += b;
}
}
cout << c; } Edited by author 19.10.2013 16:35 Edited by author 19.10.2013 16:35 if n=10 then first column is that: 2 3 4 5 6 7 10 11 12 13 AC'ed authors, how could you fix this? Try to do all calculations in integer numbers I even replaced all the doubles with integers. But the result is the same. In my formula, overflow is possible even in long long, if computed straightforwardly. So, check that in your algo no overflow occurs. #include <stdio.h> #include <vector> #define pb push_back #define For(i,n) for(int i=0;i<n;i++) using namespace std; int main() { int n,m,k; vector < int > w; vector < int > v; scanf("%d%d%d",&n, &m, &k); For(i,n) { int x; scanf("%d", &x); w.pb(x); } For(i,m) { int x; scanf("%d", &x); x--; v.pb(x); } int ind=0; int tek=0; int ans=0; long long i=0; vector < int > solve; while (true) { if (ind<v.size() && i==v[ind]) { int kol=0; while (kol<=k && solve.size()>0) { w.pb(solve[solve.size()-1]); solve.pop_back(); kol+=w[w.size()-1]; } ind++; i++; continue; } solve.pb(w[0]); w.erase(w.begin()); i++; if (w.size()==0 || solve.size()==n)break; } printf("%d", i); } I have WA 11. My solution very similar to yours. I don't have any idea what is wrong. BTW. If you use long long, you must use %lld in printf instead %d. #include <stdio.h> int n,m,k; int w[10000]; int t[10000]; long long d; void swap(int i, int j) { int t; t = w[i]; w[i] = w[j]; w[j] = t; } int caving(int i) { int s = 0; int c = 0; int j; while ((s <= k) && (i > 0)) { i--; s += w[i]; c++; } /*for (j = 0; j < c/2; j++) { swap(i+j,i+c-j-1); }*/ return c; } int main() { int i,j; int cw, ct; #ifndef ONLINE_JUDGE freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout); #endif scanf("%d %d %d\n", &n, &m, &k); for (i = 0; i < n; i++) scanf("%d", &w[i]); for (i = 0; i < m; i++) scanf("%d", &t[i]); cw = 0; ct = 0; d = 0; do { d++; if ((ct < m) && (t[ct] == d)) { ct++; cw -= caving(cw); } else cw++; } while (cw < n); printf("%lld\n", d); return 0; } Hello, Kot! > int w[10000]; > int t[10000]; >> 1 ≤ n, m ≤ 10^5 I think yon need [100000] arrays. I had a step-by-step solution which caused TL 11. I've improved it to event-by-event solution but nothing changed. I translated it from Java to Visual C 2010 using your data loader and got WA11. Replaced w[10^4] by w[10^5] - and finally I've got TL11. I don't have any good idea and wonder about better algorithm or a bug which causes an endless loop... Could you try to fix it and write your solution result? Brute force solution works fine after some optimizations. Look at n and m limits - it is possible that Luke will drop same stones more than once. Finally my solution has been accepted. It's definitely a brute force one, but using optimization for all loops, which can be run undefined number of times. did you use binary search in your solution? "Each player has his own specified starting position", means that the starting positions of the players is different? Yes, that actually means it. You could see both positions in the last string of input. No, in test 3, they both start in the same position. if((a[2]+a[3]+a[4])%2==a[5] && (a[1]+a[3]+a[4])%2==a[6] && (a[2]+a[1]+a[4])%2==a[7]) shu bajarilguncha ketma-ketlikni o'zgartirib borasiz 0 bo'lsa 1 va aksincha 1 bo'lsa 0 Masalan: 0 1 0 1 1 0 1 for petal 0 1 0 1 1 0 1 1 0 1 for petal 0 0 1 0 0 0 1 1 0 1 for petal 1 1 1 0 1 1 1 1 0 1 for petal 1 0 0 0 1 0 0 1 0 1 for petal 1 0 1 Edited by author 30.09.2013 14:39 Mana tayyor kod!!! [code deleted] Edited by Muzaffardjan Karaev M.K _77 )))xD 11.11.2013 11:11 Edited by author 12.11.2013 19:58 Edited by moderator 24.11.2019 12:42 Can anyone please describe the test case? How can it be as low as 0.66667? - First night one good senator dies. We have 2 good senators and 1 spy. - First day senators choose to kill 2 people. They have a 66.6% chance that they get the spy and a good guy remains, 33.3% chance that the spy lives. Я один раскладывал 2*n на всевозможные множители?) "At some moment of time two players can be located in the same cell." If this occurs, who will take the number in that cell? If both of them can take,then they can meet at some point and simultaneously take the number.That will maximize their score. They move in turns, not simultaneously, so even if they end up in one cell one of them (player one) must have stepped there first and therefore he must have taken the points from that cell. Thanks []zhi(Bozhin Katsarski) I have WA#11, though my decision is consisted only from integer numbers. What is possible problem? Edited by author 11.11.2013 17:03 Edited by author 11.11.2013 17:04 Edited by author 11.11.2013 17:04 My program passed all tests from forum, but It gets WA28 Here is my code: Var ygol,arm,otkl,energy,us,ensrus,enemys,ensrzapas : int64; s : string; Function Min(x,y : int64):int64; Begin if x > y then Min := y Else Min := x; End; Procedure Oxrana; Begin if enemys = 0 then Writeln('STOP') Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else if ygol > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; Procedure Atack; Begin if us*ensrus > enemys*ensrzapas*3 then if Abs(ygol) < 10 then Writeln('FIRE ',Min(20,arm)) Else Writeln('FRONT ',Min(100,energy)) Else if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) End; Procedure Defence; Begin if enemys*20 >= Arm then if Abs(ygol) < 5 then Writeln('FIRE ',Min(20,arm)) Else Writeln('BACKWARD ',Min(100,energy)) Else Oxrana; End; Procedure Patrul; Var t : longint; Begin t := otkl; if otkl < 0 then Otkl := Otkl+360; if enemys > 0 then Defence Else if (Otkl>=160) and (otkl <= 200) then Writeln('BACKWARD ',Min(100,energy)) Else if ((otkl >= 0) and (otkl <= 20) or (otkl >= 340) and (otkl <= 360)) then Writeln('FRONT ',Min(100,energy)) Else if t > 0 then Writeln('LEFT ',Min(100,energy)) Else Writeln('RIGHT ',Min(100,energy)); End; BEGIN Readln(Energy,Arm); Readln(s); Read(enemys,ensrzapas,ygol); if Pos('A',s) <> 0 then Begin Read(us,ensrus); Atack; End; if Pos('D',s) <> 0 then Defence; if Pos('G',s) <> 0 then Oxrana; if Pos('P',s) <> 0 then Begin Read(otkl); Patrul; End; END. This test, please: 4 100 P 0 123 45 128 I hope it'll help you! :))) program spiral; var n,m,r:real; begin readln(n,m); if m>=n then begin if n=1.0 then r:=0.0 else if n=2.0 then r:=2.0 else if frac(n/2)<>0 then r:=4.0*trunc(n/2) else r:=2.0*(n-1); end else begin if m=1.0 then r:=1.0 else if m=2.0 then r:=3.0 else if frac(m/2)<>0 then r:=4.0*trunc(m/2)+1.0 else r:=2.0*m-1.0; end; writeln(r:0:0); end. const{only 49K) maxn=11; var a:array[0..maxn]of 0..9; n,m:longint; i,j,s:integer; ok:boolean; begin fillchar(a,sizeof(a),0); readln(n,m); ok:=false; if n>m then begin n:=m;ok:=true;end; n:=n-1; i:=maxn+1; while n<>0 do begin i:=i-1; a[i]:=n mod 10; n:=n div 10; end; if ok then j:=1 else j:=0; for i:=maxn downto 1 do begin s:=a[i]*2+j; a[i]:=s mod 10; j:=s div 10; end; i:=0; while (a[i]=0)and(i<>maxn) do i:=i+1; for j:=i to maxn do write(a[j]); end. var m,n,y:real;b:boolean; begin readln(m,n); b:=false; if m>n then begin y:=m;m:=n;n:=y;b:=true end; if m=0 then begin writeln(0);halt;end; if frac(m/2)<>0 then y:=int(m/2)*4 else y:=int((m-1)/2)*4+2; if b then writeln(y+1:0:0) else writeln(y:0:0); end. #include <stdio.h> #include <math.h> int main(void) { unsigned int n, m, answer; scanf("%u %u", &n, &m); if (m >= n) answer = 2 * (n - 1); else answer = 2 * (m - 1) + 1; printf("%u\n", answer);
return 0; } Ok, same solution after some thinking. And it is working, just remember about huge numbers you are getting in the input #include <iostream> using namespace std; int main() { long long nN, nM; cin >> nN >> nM; if(nM >= nN) cout << 2*(nN-1); else cout << 2*(nM-1)+1; return 0; } Edited by author 12.11.2008 20:43 Edited by author 12.11.2008 20:44 Shortest sol (C language): main() { unsigned n, m; scanf("%u%u", &n, &m); printf("%u", n <= m ? 2 * n - 2 : 2 * m - 1); } #include <iostream> using namespace std; long long n,m; int main() { cin>>n>>m; if (m>=n) cout<<2*(n-1); else cout<<2*(m-1)+1; } My Solution program Ural1224; var n,m:int64; begin readln(n,m); if n<=m then writeln(n shl 1-2) else writeln(m shl 1-1); end. import java.io.*; import java.util.*; public class www { public static void main(String[] args) throws IOException{ PrintWriter out = new PrintWriter(System.out); Scanner in = new Scanner(System.in); long n = in.nextInt(); long m = in.nextInt(); out.println(m>=n ? 2*n-2 : 2*m-1); in.close(); out.close(); } } Edited by author 27.08.2013 23:07 ee munaqa bo'mag'ur masalaga bosh qotirish shartmi? При компиляции примера выдает ответы такие как указаны в примере. Но при добавлении на сайт выдает ошибку. Не могу понять почему. Подскажите пожалуйста в чем проблема? import java.io.*; import java.math.BigDecimal; public class SqrtDif {
public static void main(String[] args) throws IOException { new SqrtDif().run(); }
PrintWriter out;
void run() throws IOException { out = new PrintWriter(new OutputStreamWriter(System.out)); byte bKbd[] = new byte[256]; int iCnt = 0; String szStr; try { iCnt = System.in.read(bKbd); } catch (IOException ex) { System.out.println(ex.toString()); } szStr = new String(bKbd, 0, iCnt); String[] Str = szStr.trim().split("\\D+"); double dStr; int i = Str.length-1; while (i>=0) { dStr = Double.parseDouble(Str[i]); BigDecimal bigDecimal = new BigDecimal(Math.sqrt(dStr)); bigDecimal = bigDecimal.setScale(4, BigDecimal.ROUND_HALF_UP); out.print(bigDecimal.toPlainString()+"\r"); i--; } out.flush(); } } I got WA#22. What is possible problem here? Precision issues are quite possible in this problem - so, try to solve it in integer numbers. But I saw AC solution in double without epsilon :) If you're quite lucky or tests are weak - it is possible, but anyway quite risky on the real contest. 4 3 1 4 2 answer : 3 12 1 3 5 6 4 1 3 5 7 10 8 2 answer : 11 8 8 2 5 8 1 3 4 5 answer : 4 9 5 3 2 5 4 7 9 2 1 answer : 9 10 2 2 4 4 5 8 7 9 9 1 answer : 1 Edited by author 10.11.2013 18:43 you should set distance of station 1 = 0, as input: distance from 1 to 2 = 2 3 1 1 1 output is 0 and I ignored this condition. The value of N is <= 50, so we are talking about a 100 digit number atmost.....how then the upper limit of S is 1000.....shouldn't it be 900.....or are we supposed to return 0 when (2*N*9) < S. Am I missing something ????? Edited by author 10.11.2013 01:07 Nevermind.....I solved it..... Few useful insights :- (i) if S > (2*9*N) output 0; (ii) if S = 0 output 1; (otherwise you would get WA for test 5). Edited by author 10.11.2013 02:27 Is n no more than 100? The time complexity of my program is O(n*n), why does it take so much time to run my program?(0.531s) Do we need O(n*log(n)) to solve this problem? Maybe your program do a lot of iterations? You can skip some iterations after you found an user... 1<=n<=100 :) |
|