Common BoardCan somebody give some hints about that test? My mistake. Forget to add two registers (M and N). Dont have any idea how that happened XD Dear All, I am a student and I got an assignment from my teacher to run "1409 Two Gangsters". I write Python program v.2.7 as per following codes. I run the program many times, but it still showed "Runtime Error". I could not fix it. It would be appreciated if someone can help me. Thanks. # 1409 Two Gangsters (Created: 24th June 2015 / Python 2.7) # -------------------- Start of Program -------------------- # # Set initial values total = 0 # total number of cans shot by Harry and Larry Harry = 0 # the number of cans shot by Harry Larry = 0 # the number of cans shot by Larry h = 0 # the number of cans that were not shot by Harry l = 0 # the number of cans that were not shot by Larry Harry = int(input("Please enter the number of cans shot by Harry: ") Larry = int(input("Please enter the number of cans shot by Larry: ")
# Calculation of "The number of cans that were not shot by Harry and Larry" total = Harry + Larry -1 h = total - Harry l = total - Larry # Output print "-"*100 print "Total number of cans are : ", total print "The number of cans that were not shot by Harry and Larry are ", h, "and", l, "respectively." print "-"*100 # -------------------- End of Program -------------------- # My code got WA7. const Nmax=100500; var Dp:array[1..Nmax] of longint; A,V:array[1..Nmax] of longint; N,i:longint;
BEGIN readln(N); for i:=1 to N do begin read(A[i]); Dp[a[i]]:=Nmax+5; end;
Dp[a[n]]:=0; V[a[n]]:=0; for i:=N-1 downto 1 do begin if(Dp[a[i]]>Dp[a[i+1]]+1) then begin Dp[a[i]]:=Dp[a[i+1]]+1; V[a[i]]:=a[i+1]; end; end;
write(a[1],' '); i:=V[a[1]]; while(i<>0) do begin write(i,' '); i:=V[i]; end; END. #include<iostream> int main() { using namespace std; unsigned long long n,id[10000],x; int m[100],y,i,j; cin>>n; for(i=0;i<n;i++) cin>>id[i]>>m[i]; for(i=0;i<n;i++) { for(j=i;j<n;j++) { if(m[i]<m[i+1]) { x=id[i]; id[i]=id[i+1]; id[i+1]=x; y=m[i]; m[i]=m[i+1]; m[i+1]=y; } } }
for(i=0;i<n;i++) cout<<id[i]<<" "<<m[i]<<"\n"; return 0; } i try use hungary to get some line use more student,than try the no use student,but wa on #12,pls help me! [delete] Edited by author 23.06.2015 16:37 Edited by author 23.06.2015 16:37 var n,m,i,j:integer; a:array[1..1000]of integer; b:array[1..1000]of real; begin read(n,m); for i:=1 to m do readln(a[i]); for j:=1 to n do begin for i:=1 to m do begin if j=a[i] then b[j]:=b[j]+1; end; end; for i:=1 to n do begin b[i]:=(b[i]/m)*100; writeln(b[i]:0:2,'%'); end; end. read(n,m); ---> readln(n,m); try this Hi, how do you fixed this test? Remember that X ONLY applies to A and Y ONLY applies to B. For example: 7 5 11 Your answer can be 6 5, but it cant be 5 6. Just use it to solve this problem. import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class T1880 { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); List<Integer> an=new ArrayList<Integer>(); List<Integer> bn=new ArrayList<Integer>(); List<Integer> cn=new ArrayList<Integer>(); int a=sc.nextInt(); int count=0; int a1=a; while(a1-->0) { int n=sc.nextInt(); an.add(n); }
int b=sc.nextInt(); int b1=b; while(b1-->0) { int n=sc.nextInt(); bn.add(n); }
int c=sc.nextInt(); int c1=c; while(c1-->0) { int n=sc.nextInt(); cn.add(n); }
if(a>=b && a>=c) { for (Integer integer : an) { if(bn.contains(integer)&&cn.contains(integer)) count++; } }
else if(b>=a && b>=c) { for (Integer integer : bn) { if(an.contains(integer)&&cn.contains(integer)) count++; } } else if(c>=b && c>=a) { for (Integer integer : cn) { if(bn.contains(integer)&&bn.contains(integer)) count++; } }
System.out.println(count); } } Test 1: 150 50 1000 100 200 900 250 800 300 700 350 600 400 500 450 400 Answer:450 Test 2: 1 2 12 3 3 9 5 6 7 3 Answer:6 Test 3: 4 3 6 1 Answer:6 Test 4: 11 1 10 2 Answer:11 Test 5: 1000 2 2000 3 ............. ............. 1388 1418 1390 1415 1392 1412 1394 1409 1396 1406 1398 1403 1400 1400 Answer:1400 Hi, Can you please explain the test cases 2, 3, 4, 5 from your list on how do they work ? I have queries on how these answers come to the above asked test cases with respect to the logic given in the question. kindly help please! Thanks I Understood the logic myself.:) :D Можно решить задачу эмпирически. В начале найдем решения по-честному,когда пешка стоит на 1 горизонтали(т.е. игра почти завершена). Все состояния A[x,y,1] нам уже известны,а состояния A[x,y,i] i>1 неизвестны. Из очередного состояния (т.е. увеличив i и рассмотрев любые x,y-коорд. слона) будем выбирать макс. значение среди всех переходов. Если состояние,в которое мы попадаем неизвестно,то снова вызываем рекурсию,пока не попадем в известное(такое всегда будет,т.к. на каждом шаге пешка сдвигается хотя бы на 1,а состояния А[x,y,1] известны). Как только из данного состоя ния мы попадаем во все известные, то данное состояние становится известным. This problem can solve DP. DP[x,y,i] где x,y-координаты слона and i- ордината пешки. DP[x,y,1] найти легко( либо сразу съели и выигр.,либо проиграли). Ответ: DP[x1,y1,y2]. Учитываем,в какой вертикали находится пешка(первая вертикаль-нижняя строка). Рассмотрим очередное состояние(т.е. момент,когда i>1 и все состояния [х,y,j] j<i известны). Во-первых, возможно,что состояние тривиально(т.е. мы съедаем пешку). Тогда DP[x,y,i]:=1; Во-вторых, возможно,состояние непонятно. Тогда сделаем все возможные ходы слоном, пешка соответственно сдвигается на 1 или 2 позиции(в зависимости от горизонтали) и мы попадаем в предыдущую позицию(т.е. уже известную). Среди таких переход выбираем переход с макс. итогом( особый случай это горизонталь 2,где пешка может сходить на 2 клетки, но суть та же).Так же не следует забывать,что мы можем перегородить дорогу пешки. В этом случае нам(слону) ничья как минимум обеспечена. Сложность O(n^4) (n*n- размеры поля; параметр i<=n, все переходы - это <=2*n позиций(не считая случая с 2 горизонталью,но это реально не влияет), позиций слона n*n). Edited by author 22.06.2015 13:50 Edited by author 22.06.2015 13:51 Edited by author 22.06.2015 13:55 It's problem has mathematical solution in O(1). You must analyze several variants ( when y2=1,2,3,>=4 ) and find strategy for white. I get "wrong answer" for test №3: 2687809 17:47:13 28 июл 2009 kiriloff 1002 C# Wrong answer 3 0.109 1 129 КБ Can you help me, what problem of this? I'm failing the same test. Do you run custom unit tests on your code? I have a few tests I run on mine. perhaps between the two of us we can come up with some edge cases for our own solutions. Here are some of my own tests, They ensure that my solution can get through this sites first two tests. maybe you can spot an edge case and suggest a new test to perform. test 1 number: 1268432063036979073 vocabulary: i am the bone of my sword sandwitch casting service it one expected answer: i am the bone of my sword test 2 number: 7325189087 vocabulary: it your reality real our expected answer: reality our test 3 number: 4294967296 vocabulary: it your reality real our expected answer: No solution. test 4 number: 27386428376 expected answer: No solution. #include<iostream> #include<string> using namespace std; string Convert(string c) { unsigned int i; string number=""; for( i=0;i<c.size();i++) { if(c[i]=='i'||c[i]=='j') number=number+"1"; else if (c[i]=='a'||c[i]=='b'||c[i]=='c') number=number+"2"; else if(c[i]=='d'||c[i]=='e'||c[i]=='f') number=number+"3"; else if(c[i]=='g'||c[i]=='h') number=number+"4"; else if(c[i]=='k'||c[i]=='l') number=number+"5"; else if(c[i]=='m'||c[i]=='n') number=number+"6"; else if(c[i]=='p'||c[i]=='r'||c[i]=='s') number=number+"7"; else if(c[i]=='t'||c[i]=='u'||c[i]=='v') number=number+"8"; else if(c[i]=='w'||c[i]=='x'||c[i]=='y') number=number+"9"; else if(c[i]=='o'||c[i]=='q'||c[i]=='z') number=number+"0"; } return number; } int main() { string input_number = "0"; int no_words; int counter = 0; while(input_number != "-1") { string input_number; cin >> input_number; if(input_number == "-1") break; cin>>no_words; string *words; words = new string[no_words]; for (int i=0;i<no_words;i++) { cin>>words[i]; } string *converted_words; converted_words= new string [no_words]; for (int i=0;i<no_words;i++) converted_words[i]=Convert(words[i]); for (int i=0;i<no_words;i++) { if(converted_words[i] == input_number) { cout<< words[i] << " "; counter ++; break; } } if(counter == 0) { cout<<"no solution"; break; } } return 0; } could someone please point out the foolishness. this I think: cout<<"no solution"; cout<<"No solution"; actually should be "No solution." remember the period. May be you should decrease the counter. counter--; as you are trying to compare counter==0; Another issue: Major one, Your code is literally comparing the converted numbers directly to the input number. If no number is matched you have to check all the possible permutations of the converted number array. The question is asking minimum number of words required to match the number. (GOT IT?) what's test2? my program has passed test 1 and 3 as i know thx me too who know what is test2 ??? :) try dis: input: 4 10 10 10 5 10 0 -1 -1 ouput: 3 Try any test with ansewer 2. Example: 3 4 4 3 5 0 0 output: 2 sc.useDelimiter(""); .. sc.next().charAt(0) might help 1. Calculate S 2. Total S = S+S/k+S/k^2+S/k^3.. |
|