Common BoardA very good resource, but it still very hard for me to understand though...:( very thanks, I understood! Thanks for the hints: using dynamic programming. Simple but interesting problem. There are two ways to find angle: geometrically (i made it this way) or computationally :). Что такое тест № 3? мой алгоритм не прошел этот тест!!! Вообще где найти разъяснения к номерам тестов?? какие-такие разъяснения? раз не прошел 3 тест значит где-то у тебя косяк. Никакой не косяк. Реально тест №3 неправильный. Вот корректное решение: считываем в два массива А и В. Потом цикл по элементам А, и для каждого А(и) пытаемся найти такое В(ж), чтобы А(и)+В(ж)==10000. И получаем ВА. Бред. (поиск бинарный так как отсортированы массивы). #include <iostream> using namespace std; int cmp(const void*A,const void *B){ long t=*(long*)A-*(long*)B; if (t>0) return 1; if (t==0) return 0; if (t<0) return -1; } int main(void){ long N,M,i,j; long *A,*B; long * C; cin>>N; A=new long[N]; for(i=0;i<N;i++) cin>>A[i]; cin>>M; B=new long[M]; for(i=0;i<M;i++) cin>>B[i]; bool t=false; for(i=0;i<N;i++) { j=10000-A[i]; C=(long*)bsearch(&j,B,M,sizeof(long),cmp); if(C!=NULL) if(A[i]+*C==10000){t=true; break;} } if(t)cout<<"YES"; else cout<<"NO"; cout<<endl; system("pause"); return 0; } Очевидно условия некорректны. В условии сказано,что массивы упорядочены. Но достаточно дописать в мое решение qsort(A,N,sizeof(long),cmp); qsort(B,M,sizeof(long),cmp); И вуаля все просто, и получаем АС. Авторы проверяйте условия, или хотя бы читайте форум иногда. Тут нередко попадаются задачи с корявыми тестами, которых не должно быть по условию. Edited by author 03.12.2010 03:00 Процедура bsearch предполагает, что массив должен быть отсортирован в неубывающем порядке, мне не совсем понятен твой компоратор, фактически он ничего не меняет, так процедура bsearch и сравнивает по умолчанию. То есть когда ты отсортировал массив по своему компоратору, ты, фактически, инверитровал его и привел к такому виду, что процедура bsearch будет работать правильно. Попробуй на своей первоначальной программе: 9 3 5 15 20 100 900 5000 9983 15000 9 7000 549 58 17 8 4 0 -10 -30 Правильный ответ: ΥΕS (9983+17) И да:"Если вы не можете решить задачу, значит вы не можете её решить". попробовал на своей программе #include <iostream> using namespace std; int main() { int n; cin >> n; int *a = new int[n*2]; for (int i = 0; i < n*2; i++) cin >> a[i]; for (int i = 0; i <n; i++) for (int j = n; j < n*2; j++) if (a[i]+a[j] == 10000) { cout << "YES" << endl; delete [] a; exit (0); } cout << "NO" << endl; delete [] a; return 0; } Выдало YES, к тому же такой алгоритм хоть и можно назвать затратным, но он рабочий. Кто в теме, приведите хотя бы один пример НЕбогатой строки. Буду признателен try brute force for n>7 Спасибо. И поздравляю как первого (и пока единственного) решившего) Give me some tests or advices, please. Got WA4, cause ignore situation \par" Input: There is no "q in this sentence. \par" "Talk child," said the unicorn. She s\"aid, "\thinspace `Enough!', he said." \endinput Output: There is no q in this sentence. \par`` ''Talk child, said the unicorn. She s\"aid, ``\thinspace `Enough!', he said.'' \endinput To admins: please add some rules, which format of output should be, because this example from one month shows me nothing. 1) number of spaces must be 3 everywhere except 1,2,3,4,5,6,7,8,9? 2) we must count day of week using normal calender? Rules about it are full, or some items are omitted??? 3) What is in test 10?? P.S. Is this correct for: 7 1 2006 mon.......2....9...16...23...30 tue.......3...10...17...24...31 wed.......4...11...18...25 thu.......5...12...19...26 fri.......6...13...20...27 sat.....[.7]..14...21...28 sun...1...8...15...22...29 Or correct is: mon........2....9...16...23...30 tue........3...10...17...24...31 wed........4...11...18...25 thu........5...12...19...26 fri........6...13...20...27 sat......[.7]..14...21...28 sun...1....8...15...22...29 ????? I mean number of spaces. Edited by author 03.03.2007 11:41 I think you should not count space characters but rather use alignment like in sample. The problem is that there is no information about this case in samples. #include <iostream> #include <string> #include <cstdlib> #include <cmath> #include <sstream> #include <vector> #include <stdio.h> using namespace std; int main() { string s=""; vector <long double> vec; cout<<vec.size(); long double j; char c; stringstream ss(""); for (int i=0;i<256000;i++)//This is here so I can handle the size of the stream input { cin.get(c); s+=c; } //Now I know I am working on 256KB ss<<s; while(ss>>j) { j=sqrt(j); vec.push_back(j); } for (int k=vec.size()-1;k>=0;k--) { cout.precision(4); cout<<fixed<<vec[k]<<endl; } return 0; } I should add a test, if we are in the end of file before the 256000. Otherwise, it'll wait for 256000 char to enter InputStream is = System.in; byte[]b = new byte[1000_001]; int L = is.read(b)-1; while(b[L]<48 || b[L]>57) L--; int i=0; double D = Math.sqrt(0.5); double x=0; double y=0; // 1 2 3 4 5 6 7 8 9 double[] shftx = new double[]{0,-D, 0, D,-1, 0, 1,-D, 0, D}; double[] shfty = new double[]{0,-D,-1,-D, 0, 0, 0, D, 1, D}; while(i<=L && b[i]!=48 && b[i]!=0){ x+=shftx[b[i]-48]; y+=shfty[b[i]-48]; i++; } System.out.println(String.format("%.10f %.10f", x, y)); Pairs in output should be ordered: in each pair first the name of a person writing the statement and then the name of a person preparing the tests. Solution printing unordered pairs gets wa3. My solution got wa1 because of this)) I got WA 14. I don't understand why? Please give me some tests or explain where is my mistake. #include <iostream> using namespace std; int main (){ int a; int sum; cin >> a; if (a<1 && a>=-10000){ for (int i = 1; i >= a; i--){ sum = sum + i; }; } else if (a>=1 && a<=10000) { for (int i = 1; i <= a; i++){ sum = sum + i;
}; }; cout << sum; return 0; } при: N(a) -- sum 10000 -- 50005000 1 -- 1 0 -- 1 -1 -- 0 -3 -- -5 -10000 -- 50004999 Edited by author 16.07.2015 12:55 Edited by author 16.07.2015 12:56 #include <iostream> using namespace std; int main() { int a, b; cout << "Enter 'a': "; cin >> a; cout << '\n'; cout << "Enter 'b': "; cin >> b; cout <<'\n'; cout << a + b; return 0; } Edited by author 07.06.2015 21:38 Edited by author 07.06.2015 21:38 Don't output "Enter a" or something like that Don't output "Enter a" or something like that Значения a и b вводятся через пробел, поэтому надо использовать только cin >> a >> b; 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 <stdio.h> #include <math.h> main() { int a=0; float b=0; while (!feof(stdin)) { scanf("%d", &a); b=sqrt(a); if (feof(stdin)) printf("%.4f\n",b); } } It works fine at my PC. But it keeps saying wrong answer? #include <stdio.h> #include <math.h> main() { int a=0; float b=0; while (!feof(stdin)) { scanf("%d", &a); b=sqrt(a); printf("%.4f\n",b); } } You should use a long long data type, because the int type supports only 2^32 as max. Please, read the contraints of the problem. There says that the number could be as big as 10^18 (a lot bigger than 2^32). Try with long long. Hope it be useful for you. //if 'double s[130196]' before 'int main()' - all is OK!! //but if 'double s[130196]' in 'int main()' then Runtime error (stack overflow)!!!!!!! //------------------------------------------------- //AND MAGIC №2: //any number after 130196 (for example 130196,130197...) in 'double s[130196]' - all is OK!! //BUT numbers before 130196, for example 130195, 130194... then Runtime error (access violation)!!! //------------ //on the internet people use 'double s[131072]' - it is 2^17, why???? if i can use 130196 //------------------ #include <iostream> #include <iomanip> #include <cmath> using namespace std; double s[130196];// if 130195 or < then Runtime error (access violation)!!! int main() { //double s[130196]; - if in 'int main()' then Runtime error (stack overflow) int t = 0; while (cin>>s[t]){t++;} while(t>0){cout<<fixed<<setprecision(4)<<sqrt((double)s[--t])<<endl;} return 0; } //why why why ??)) Edited by author 14.07.2015 17:12 Array from main function is kept in stack memory, and this memory is limited. You should declare it as global, or increase stack size. import java.util.Scanner; public class _1370 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int digitos = in.nextInt(); int cliques = in.nextInt(); String saida = ""; String parte2 = ""; for (int i = 1; i <= cliques; i++){ saida += in.nextInt(); } for (int i = cliques+1; i <= digitos; i ++){ parte2 += in.nextInt(); } parte2 += saida; System.out.println( parte2.substring(0,10) ); } } you are using in.nextInt() to get the input from the user for a String. That is used for integers. You should be using in.next() or in.nextLine() for String. Can anybody send me the fifth test of this problem? My program always crushes on it. I think it's something wrong when input my data int size; struct point{ int number; bool pr; }; vector<point> matrix[1000]; int main(){ int name1, name2; point c; char hg='0'; vector<int> victims; cin >> size; while (hg != 'B'){ cin >> hg; if (hg != 'B'){ cin >> name2; name1 = atoi(&hg); c.pr = true; c.number = name2 - 1; matrix[name1 - 1].push_back(c); c.pr = false; c.number = name1 - 1; matrix[name2 - 1].push_back(c); } } for (int i = 0; i < 4; i++) cin >> hg; while (std::cin >> name1) victims.push_back(name1 - 1); 987654321 => white 123456789 => white 666 => black 999 => white 8 => black 13 => white 19 => white 5 => white Edited by author 26.12.2015 22:50 |
|