Common Boardкак перевести код под с++ в блок схему This is my code ----------------------------------------- var j,i: longint; a: array[1..100000000] of real; begin i:=1; while not EOF do begin read(a[i]); i:=i+1; end; for j:=i-1 downto 1 do writeln(sqrt(a[j]):0:4); end. ----------------------------------------- Why is it wrong? can anyone please explain? thanks a lot Edited by author 10.03.2019 13:21 #include<bits/stdc++.h> #include<math.h> using namespace std; int main() { long long int i,j,k,s; double a,b,c,d; scanf("%lld %lld %lld %lld",&i,&j,&k,&s); if(s>=0) { d=sqrt(s); printf("%.4f\n",d); } if(k>=0) { c=sqrt(k); printf("%.4f\n",c); } if(j>=0) { b=sqrt(j); printf("%.4f\n",b); } if(i>=0) { a=sqrt(i); printf("%.4f\n",a); } return 0; } Why do you think there are only four numbers in input? Why do you think a number can be negative? If you are new to OJ system... The point is, the system will input any case that satisfies its question, not only the sample input. Therefore, there might not be only 4 numbers for you to consider. It may input 100 numbers, which your code obviously cannot give the correct output. can anyone send me a test please? semenanufriev@gmail.com Easy to solve with linear programming ## Russian ## ## 1 Идея ## 1) Представим число A в виде 10x+m1, где x - число десятков m1=2 (m1 не может быть равно 1, так как в этом случае искомое число A нечетное и на 2^N не разделится). Разделим число на 2, получим A=5x+1. 2) Пусть x=10y+m2, где y - число сотен. После подстановки получим A=5(10y+m2)+1=50y+5m2+1. Чтобы число A разделилось на 2, надо, чтобы m2 было нечетным. Следовательно выбираем m2=1. После деления на 2 получим: A=(50y+5*1+1)/2=25y+3. 3) Пусть y=10z+m3, где z - число тысяч. После подстановки получим A=25(10z+m3)+3=250z+25m3+3. Чтобы число A разделилось на 2, надо, чтобы m3 было нечетным. Следовательно выбираем m3=1. После деления на 2 получим: A=(250z+25*1+3)/2=125z+14. 4) Пусть z=10t+m4, где t - число десятков тысяч. После подстановки получим A=125(10t+m4)+14=1250t+125m4+14. Чтобы число A разделилось на 2, надо, чтобы m4 было четным. Следовательно выбираем m4=2. После деления на 2 получим: A=(1250t+125*2+14)/2=625t+132. Далее процесс повторяется N раз. Последовательность mN...m4m3m2m1 образует ответ. Алгоритм требует применения длинной арифметики. Общее решение достигается за N шагов. ## 2 Алгоритм ## Пусть m[1]=2; a_[1]=5; b_[1]=1; Цикл i = от 2 до n нц m_[i]=(если b_[i-1] нечетное, то 1, иначе 2) b_[i]=(если b_[i-1] нечетное, то (a_[i-1]+b_[i-1])/2, иначе (2*a_[i-1]+b_[i-1])/2) (так как a_[i-1] нечетное всегда по определению) a_[i]=a_[i-1]*5; кц ## English (in short) ## ## 1 The Idea ## 1) Let me A = 10x+m1, where x - number of Tens m1=2 (m1<>1, as A - odd). Division A in 2, let's receive A=5x+1. 2) Let me x=10y+m2, where y - number of Hundreds. Then A=5(10y+m2)+1=50y+5m2+1. if A%2==0, m2 is odd. Then m2=1 and A=(50y+5*1+1)/2=25y+3. 3) Let me y=10z+m3, where z - number of Thousand. Then A=25(10z+m3)+3=250z+25m3+3. if A%2==0, m3 is odd. Then m3=1 and A=(250z+25*1+3)/2=125z+14. 4) Let me z=10t+m4, где t - number of Tens thousand. Then A=125(10t+m4)+14=1250t+125m4+14. if A%2==0, m3 is even. Then m3=1 and A=(1250t+125*2+14)/2=625t+132. Further process repeats N time. Sequence mN... m4m3m2m1 forms the answer. The algorithm demands application of long arithmetics. ## 2 The Algo ## Let me m[1]=2; a_[1]=5; b_[1]=1; for i = 2 to n begin m_[i]=(if b_[i-1] is odd, then 1, else 2) b_[i]=(if b_[i-1] is odd, then (a_[i-1]+b_[i-1])/2, else (2*a_[i-1]+b_[i-1])/2) a_[i]=a_[i-1]*5; end thank you! excellent idea! Можно проще. Индукция: для любого n существует число x(n) из 1 и 2 длиной n, делящееся на 2^n. База: n=1=>x(1)=2. Переход n->n+1: если x(n) делится на 2^(n+1), то в качестве x(n+1) можно взять x(n+1)=2x(n) (т.е. слева приписать 2), иначе x(n+1)=1x(n). Edited by author 10.03.2019 13:22 whats in test 8 ? cant find out :( try to use this one 5 2 3 0 4 5 Hint: when the pirate becomes the current best option, he is also being compared. Thus in the test case above pirate 1 will be compared 2 times, while pirate 3 will be compared 3! GL!!! Try this test 6 2 2 2 1 1 1 ans: 4 using System; class Entrypiont { static void Main() { string[] Input = Console.ReadLine().Split(' '); int a = Convert.ToInt32(Input[0]); int b = Convert.ToInt32(Input[1]); int c = Convert.ToInt32(Input[2]); if(((c-1)%a)==((c-1)%b) && ((c - 1) % a) == 0) { int x=1, y=1, z=1; while (true) { if(Math.Pow(x,a)+ Math.Pow(y, b)== Math.Pow(z, c)) { Console.Write(x); Console.Write(y); Console.Write(z); break; } else { if(Math.Pow(x, a) + Math.Pow(y, b) >Math.Pow(z, c)) { z++; } else { if (x >= y) { y++; } else { x++; }
} } } } Console.ReadLine(); } } Test: ABBCC Answer: BB It's not that test( I have WA#17 but my prog writes "BB" on this test I had WA on this test. I used manacher algorithm from e-maxx, in realization on site is one mistake, what ruin solution on this test, after correcting i got AC #include <iostream> #include <cmath> #include <vector> #include <algorithm> #include <string> #include <iomanip> #include <set> using namespace std; int main() { int x1, x2, y1, y2, x3, y3, l; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> l; // h = 2/s3 в€љp(p-s3)(p-s1)(p-s2), int a = y1 - y2, b = x2 - x1, c = x1 * y2 - x2 * y1; double s1 = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), s2 = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)), s3 = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); double p = s1 + s2 + s3; p /= 2; double ans = (2 / s3 * sqrt(p * (p - s3) * (p - s1) * (p - s2))); if (max(s1, s2) * max(s1, s2) > min(s1, s2) * min(s1, s2) + s3 * s3) { ans = min(sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))); } if (s3 == 0.0) { ans = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) *(y1 - y3)); } printf("%0.2f\n", max(0.0, ans - l)); printf("%0.2f\n", max(0.0, max(sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3)), sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3))) - l)); } k=2 => k-1 = 1. But everything is divisible by 1, what's wrong? Not all numbers could be written in binary number system #include<iostream> #include<cmath> #include<iomanip> #define pi 3.1415926 using namespace std; int main(){ float side,len; cin>>side>>len; if(len>(side/2)*sqrt(2)){ cout<<fixed<<setprecision(3)<<side*side; return 0; } if((side/2)>=len){ cout<<fixed<<setprecision(3)<<len*len*pi; return 0; } float cosx=(side/2)/len; float sinx=sqrt(1-cosx*cosx); float cosA=2*sinx*cosx; float theta=acos(cosA); cout<<fixed<<setprecision(3)<<len*len*0.5*theta*4+sqrt(len*len-(side/2)*(side/2))*(side/2)*4;
return 0; } qalesan nima uchun o'zbek tilida gapirasiz? GOOD peoples Please help me! I have got WA#5! I used DSU!! My program gives right answer for all my tests! But again WA#5 and I can not found my mistake! I shall wait advices or tests! Thank you advance!!! I have got AC!!! =) What test you used to check it? 4 4 1 2 1 2 2 3 3 4 3 1 2 3 good luck!!! just consider this condiction: 2 A\A B\A the correct output is A A B A but if you are mistaken, you will output A A Of course, folders on different depths (or in different subtrees) can have equal names. (look at disk tree on your computer). Edited by author 30.10.2004 22:38 Why couldn't it be : B A A ?? All the given directory addresses start from same common root Please help me. TLE #39 EDIT: GOT AC how The least prime divider in tests is less than 1.1E6 (but checking till 8E7 will still got AC) I think that most people trying to solve this problem will try to deal with two problems, they are: 1. How to calculate a[n] fast? 2. How to find those n that a[n] is the maximum in [1...n]? Here is my method. 1. Calculating a[n] (without calculating a[1...n-1]). Directly calculation will lead to a long time. But, after some observation, I found that: a[4n] = a[n] a[4n + 1] = a[2n] + a[2n + 1] = 2a[n] + a[n + 1] a[4n + 2] = a[n] + a[n + 1] a[4n + 3] = a[n] + 2a[n + 1] So, a[4n] to a[4n + 3] could be presented as the linear form of a[n] and a[n + 1]. We will soon realise that, a[2^k n] to a[2^k n + (2^k - 1)] could also be presented as linear form of a[n] and a[n + 1]. So, pre-calculation is done to calculate all the linear forms of a[65536n] to a[65536n + 65535]. This will take about O(65536 * 2) time. After this pre-calc, calculation for any number K will go very fast. 2. Finding the maximum. After listing some of the 'maximum index', we found that: 1 3 5 9 11 19 21 35 37 43 ...... Maybe my math is not so good, so I could not find so useful properties in the array, but I noticed one thing: ------------------------------------------------------------------------------------------ Every 'maximunm index' could be presented as its max 2-power and some former 'maximum index'. ------------------------------------------------------------------------------------------ Sorry for my poor English, let's take a look at the examples: 1 3 = 2 + 1 5 = 4 + 1 9 = 8 + 1 11 = 8 + 3 19 = 16 + 3 21 = 16 + 5 35 = 32 + 3 37 = 32 + 5 43 = 32 + 11 ...... So, we just need to use every 2^k number to ITERATE the list of 'maximum index'. As the list is of size O(Log N), the algo runs quite fast. With above methods, I got AC in 0.046 sec. Well, if my algo is too stupid for you, don't hesitate to post your algo here. Have fun and good luck. #include <iostream> using namespace std; char paper[4][4], pass[4][4],rPass[16],TempPaper[4][4]; int v, i, j; void check(char paper[4][4], char pass[4][4]) { for (int j = 0; j < 4; j++)// X/. { for (int i = 0; i < 4; i++) { if (paper[j][i] == 'X') { rPass[v] = pass[j][i]; v++; } } } } int main() { for (int j = 0; j < 4; j++) //paper cin { for (int i = 0; i < 4; i++) { cin >> paper[j][i]; } } for (int j = 0; j < 4; j++)//зашифрованый пароль { for (int i = 0; i < 4; i++) { cin >> pass[j][i]; } } for (int j = 0; j < 4; j++)//temp { for (int i = 0; i < 4; i++) { TempPaper[j][i] = paper[j][i]; } } check(paper, pass); for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { int t=0, y; if (j == 0) { int u = 3; for (y = 0; y < 4; y++) { paper[t][u] = TempPaper[0][y]; t++; } } if (j == 1) { int u = 2; for (y = 0; y < 4; y++) { paper[t][u] = TempPaper[1][y]; t++; } } if (j == 2) { int u = 1; for (y = 0; y < 4; y++) { paper[t][u] = TempPaper[2][y]; t++; } } if (j == 3) { int u = 0; for (y = 0; y < 4; y++) { paper[t][u] = TempPaper[3][y]; t++; } } } check(paper, pass); for (int j = 0; j < 4; j++) { for (int i = 0; i < 4; i++) { TempPaper[j][i] = paper[j][i]; } } } return 0; } |
|