|
|
a = int(input()) b = int(input()) if a %2==1 and b%2==1: print(int((b-a)/2+1)) else: print((b-a)//2) Why WA?? What if a = 2 and b = 3? The answer will be 1 but your code will give 0. Now fix it. a=int(input()) b=int(input()) i=a w=0 while i<=b: w=w+1 i=i+2 if (a%10==0): w=w-1 print(w) first = int(input()) second = int(input()) count = 0 for i in range(first, second + (second % 2 != 0), 2): count += 1 print(count) Edited by author 07.01.2018 14:22 Edited by author 07.01.2018 14:23 For 2 4 it should be days 2 and 4. For 100 200 it shoould be 100, 102...148(count must be 25 already)...200(count is 51). Janus brokes fuses every ODD day. There is 1 odd day in interval [2..4] Hmm... I see that I just did not understand the task clearly. For me it was like day 2 is the first day, but it is just the starting point of counting... Thanks. Hello! Why I got WA? I can't understand :| IMO this must work... Tnx all. ---------------------------------------------------- dayTotal = (LastDay - FirstDay) + 1; for(counter = 1; counter <= dayTotal; counter++) { n = counter % 2; if(n != 0) fuse++; } ----------------------------------------------------- #include <iostream> int main() { int a,b; int answer=0; std::cin>>a>>b; if(a%2==0)a++; for(int i=a;i<=b;i+=2) answer++; std::cout<<answer; return 0; } JDBaha your solution is wrong. for 2 4 it says 1. Edited by author 15.10.2016 15:10 Edited by author 15.10.2016 15:10 Hello, here is my code using System; public class Program { public static void Main(String[] args) { var a = Convert.ToInt32(Console.ReadLine()); var b = Convert.ToInt32(Console.ReadLine()); var ans = (b-a + 1) / 2; if (b % 2 > 0) ans++; Console.WriteLine(ans); } } I can not find out the problem :( I can't understand what's wrong in my code, it write 51 instead of 50 #include <iostream> using namespace std; int main() { unsigned short a, b, c; cin >> a >> b; c = (b - a) + 1; if(c % 2 == 0) cout << c / 2; else cout << (c / 2) + 1; /// 1! 2 3! 4 5! 6 7! 8 9! 10 11! 12 13! 14 15! return 0; } #include <iostream> using namespace std; int main() { int aNumber, bNumber; cin>>aNumber; cin>>bNumber; if(bNumber > aNumber) { cout<< ((bNumber-(aNumber + (aNumber%2? 0:1) ))/2) + 1; } else if(bNumber == aNumber) { cout<<"1"; } } what might be test case #4 ? Try this: 4 4 The answer should be 0. Edited by author 02.04.2015 00:59 #include <iostream> using namespace std; int main() { int a,b ; cin>>a>>b ; int c=b-a+(a%2)+(b%2) ; cout<<c/2 ; } del Edited by author 06.01.2015 21:37 Find the solution and explanation of this task in manyprogrammingtutorials.blogspot.com #include <iostream> using namespace std; int main(void){ int a,b,res; cin>>a>>b; res = (b-a +1)/ 2; if((b-a +1)&1 and b&1) res++; cout<<res<<endl; return 0; } I've got AC by stupid brute force, like if (i % 2) k++;. But i think that there is a easier way to solve this task. Topic. но это не тупой брутфорс, просто в четные дни он не ломает предохранители. 100-ый день четный, поэтому ответ 50, а не 51 Seriously, guys, put away correct formulas, please. If ((last day) mod 2 = 0) than formula = ((b - a)+1)/2 else formula = ((b - a) + 2) / 2 I got AC Because if we our seconf day mod = 0, it means, that we mustn't count last day, only add 1. If our second day mod 2 = 1, it means, that we must count second day, add 2. That's easy Edited by author 14.10.2012 16:23 Edited by author 14.10.2012 16:24 What it ask us to do? Who can explain me the work. Thanks. It isn`t anything complex . It gives u the beginning and ending of an interval : A and B and wants you to calculate how many digits in this interval ( including the numbers A and B ) are odd. So u see it is just as simple. Good luck. Edited by author 17.10.2004 21:12 What if a=1 and b=1? Should the answer be 1? изменил в коде одну букву и он прошёл кому нужен код kostan3@spaces.ru in second test true reult 51. The fusses blew up only in days where d%2==1 ( is something wrong with the problem description because it doesn't specify this ). program bif; var a,b,c,d:integer; i:real; begin readln (a,b); c:=((b-a)+1) mod 2; if c=0 then i:=((b-a+1)/2) else begin i:=((b-a) div 2)+1; d:=b mod 2; if d=0 then i:=i-1; end; if a=b then i:=1; writeln (i); readln; end. What does this problem mean? it's very easy to write after understand the problem. The problem is that one man is making something in every day after day.for example he will make something in first day then in third day then in 5th day an so on.you should calculate how many things he will do from A to B. A and B are integers to understand you can think that they are numbers of the day in year. sorry for mu English. Regards Похоже, что во входных строчках помимо чисел A и B присутствуют ещё и пробелы. Или другие пустые символы... You are wrong. Tests contain only two integers with exactly one end of line after each of them (no other characters). I've got AC after I added .Trim(). But there could also be another unnoticed change in my code which actually fixed it. So anyway, extra precautions would never do the harm. :) Thanks for your time examining input validity, Sandro! speak English, respect other var m,n,i,k:integer; begin readln(n,m);k:=0; for i:=n to m do if odd(i) then inc(k); writeln(k);readln; end. I'd say this is a brute force. Here is mine AC: var a,b,c:integer; begin readln(a,b); c:=(b-a+1) div 2; if (odd(b)) and (odd(a)) then inc(c); writeln(c); end. Why do you post your ACC programs here ? This is a bad practice. Edited by author 19.07.2006 16:22 This is shorter b shr 1 - a shr 1 + b and 1 (b - a) / 2 + (a % 2 | b % 2) |
|
|