#include<iostream> using namespace std; int main(){ int a,b, thief[10000],i=0; cin>>a; cin>>b; int count = 0; for (int i = 0;i<10000;i++){ thief[i] = i; // cout<<thief[i]<<" ";
} for(i=0;i<10000;i++){ //cout<<"first"<<i<<endl; if(a==thief[i]||b==thief[i+1]){ count++;
} // cout<<"thief["<<i<<"]"<<thief[i]<<"\t"<<"thief["<<i+1<<"]"<<thief[i+1]<<endl; i=i+1; //cout<<"thief"<<i<<endl;
} if(count>0) cout<<"yes"; else cout<<"no"; } This code is not very efficient. Try this code instead: #include <iostream> using namespace std; int main(){ int key1;cin>>key1; int key2;cin>>key2; if((key1%2==0) || key2%2!=0){ cout<<"yes"<<endl; } else{ cout<<"no"<<endl; } return 0; } Edited by author 01.03.2024 21:16 Edited by author 01.03.2024 21:16 i checked it manually and answer was correct. Why does if fail? Code: #include <iostream> int main(){ std::string lock1, lock2; std::string result = "yes"; int code = 1; int lock_val1, lock_val2, cur_value; bool lock_state = false; std::cin>>lock1; std::cin>>lock2; lock_val1 = std::stoi(lock1); lock_val2 = std::stoi(lock2); while (code < 10000) { if (lock_state == true){ cur_value = lock_val1; } else{ cur_value = lock_val2; } if (code > lock_val1 && code > lock_val2){ result = "no"; break; } if (code == cur_value){ break; } lock_state = !lock_state; ++code; }
std::cout << result << std::endl; return 0; } Edited by author 30.11.2021 13:19 Edited by author 30.11.2021 13:19 Edited by author 30.11.2021 13:24 Edited by author 30.11.2021 13:37 It passed, there was a typo. a,b = map(int,input().split()) if (a % 2 == 0 and b % 2 != 0): print("yes") else: print("no") because data type should be string, not integer sorry, my bad. data type is correct, but you should input like that: a=int(input()) b=int(input()) плиз напишите решение задачи 1877. Велосипедные коды please help piton 3.6 Edited by author 17.12.2018 19:09 Not piton, python ;) Я на Python решил (decide), а на плюсах(C++) то же решение не заходит(don`t work) Действительно, на С++ не проходит решение. Ни так ни сяк. I wrote a stupid solution and got wa32. Help please! How did the thief steal the bicycle ?I'm not pretty sure. Is there some one telling me ? The thief steals the bicycle if he opens the lock, that is, if the code he tries is the same as the code for the lock. Test 1: Den's keys: 0001 0000 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0001 0000 0001 0000 - bad man 0000 0001 0003 0004 - result no no no no no Test 2: Den's keys: 0002 0001 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0002 0001 0002 0001 - bad man 0000 0001 0003 0004 - result no yes no no yes In the first test all nights result is "no". That why in the first test result is no. Thanks a lot for the explanation. a=int(input()) b=int(input()) if (a%2) == 0 or (b%2) == 1: print('yes') else: print('no') /* by thinking the combinations of the two locks,we get if the password number for lock1 is even or password number for lock2 is odd, the theif could open the lock. I guess that would be the easiest ideal,right? */ #include <iostream> using namespace std; int main() { int lock1, lock2; cin >>lock1 >>lock2; if (lock1 % 2 == 0 || lock2 % 2 != 0) cout << "yes" << endl; else cout << "no" << endl; return 0; } #include <stdio.h> int main() { char a[3],b[3]; gets(a); gets(b); int x; if (a[3]=='0'||a[3]=='2'||a[3]=='4'||a[3]=='6'||a[3]=='8') x=1; if (b[3]=='1'||b[3]=='3'||b[3]=='5'||b[3]=='7'||b[3]=='9') x=1; if(x==1) printf("yes"); else printf("no"); } The two codes are just two numbers, think about it this way. If I write more, the solution will be obvious and you will get nothing. #include <stdio.h> int main() { int a, b; scanf("%d %d", &a, &b); if (a % 2 == 0 || b % 2 != 0) { printf("YES"); } else { printf("NO"); } return 0; } Posted by Deepto Shome Pritom 4 Feb 2017 21:06 Test 1: Den's keys: 0001 0000 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0001 0000 0001 0000 - bad man 0000 0001 0003 0004 - result no no no no no Test 2: Den's keys: 0002 0001 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0002 0001 0002 0001 - bad man 0000 0001 0003 0004 - result no yes no no yes In the first test all nights result is "no". That why in the first test result is no. try to understand .. happy coding Edited by author 19.07.2017 23:44 import java.util.Scanner; /** * Created by macbookpro on 2/19/15. */ public class JavaThieves877 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int c1 = Integer.parseInt(scanner.nextLine()); int c2 = Integer.parseInt(scanner.nextLine()); if(c1 % 2==0 || c2 % 2!=0 ) { System.out.print("Yes"); } else if(c1 % 2 != 0 || c2% 2== 0) { System.out.print("No"); } } } Nevermind I didn't read that this is running well:) Edited by author 21.06.2017 04:49 #include<stdio.h> int main(void){ int a, b; scanf("%d %d", &a, &b); if(a%2==0 || b%2!=0) puts("yes"); else if(a%2!=0 || b%2==0) puts("no"); return 0; } else puts("no"); is enough I used binary operations to solve the problem and I didn't manage make my algorithm faster. My algorithm is too slow (0.015 sec). Could you give me a little advice how I can optimise my algorithm? My facebook: https://www.facebook.com/dmitriy.demenev.7Time is rounded here, so you can only see results like 0.001, 0.015, 0.031, 0.046, 0.062 etc. 0.001 and 0.015 are pretty much equal, and 0.015 can mean pretty much anything between 0.002 and 0.015. Like 0.001, 0.015 is an ideal time, there's nothing to optimize here. Only starting from 0.031 the program might be considered "slightly slow". Thank you, Jane. It was really important for me. I got crazy of this runtime. It was like a bolt out of the blue xD Good luck!. Btw, sorry for my English :D raw_input() is ok input() is Runtime error from random import randint v1 = '' v2 = '' cod1 = ''.join(map(str, [randint(0, 9) for _ in range(1, 5)])) cod2 = ''.join(map(str, [randint(0, 9) for _ in range(1, 5)])) while v1 != cod1 and v2 !=cod2: n = input().split() v1 = n[0] v2 = n[1] if v1 != cod1 and v2 != cod2: print('no') print('yes') var a,b :integer; begin readln(a,b); if a mod 2 = 0 then writeln('yes') else if b = 0 then writeln('no') else if b div 2 mod 2 = 0 then writeln('yes') else writeln('no'); end. I can't understand this problem mean, someone can explain it for me? Why first test and second test have this result? Test 1: Den's keys: 0001 0000 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0001 0000 0001 0000 - bad man 0000 0001 0003 0004 - result no no no no no Test 2: Den's keys: 0002 0001 1st night 2nd night 3rd night 4th night ... ... ... All nights bike's key 0002 0001 0002 0001 - bad man 0000 0001 0003 0004 - result no yes no no yes In the first test all nights result is "no". That why in the first test result is no. Very Clear answer ! thank you :) perfect but in line "bad man" , he checks 0002 betwen "0001" and "0003" import java.util.Scanner; public class JavaThieves877 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int c1 = Integer.parseInt(scanner.next()); int c2 = Integer.parseInt(scanner.next()); if (c1 % 2 == 0 || c2 % 2 != 0) { System.out.print("Yes"); } else if (c1 % 2 != 0 || c2 % 2 == 0) { System.out.print("No"); } } } #include <stdio.h> using namespace std
void main() { __int64 a,b,i,f=0; scanf("%i64d",&a); scanf("%i64d",&b); if( ((a % 2)==0) || ( ( b % 2)== 1)) printf("yes"); else printf("no"); } it has wa32 on c But same alghoritm on delphi has ac& program Project2; {$APPTYPE CONSOLE} uses SysUtils; var a,b:integer; begin readln(a); readln(b); if( ( ( a mod 2 )= 0 ) or ( (b mod 2) = 1) ) then write('yes') else write('no'); end. Chto za fignya? +1 WTF? Scanf can sometimes convert integers to octal. ie. 0132 |
|