Common BoardCode: #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) {int spammers; char peeps[33][101]; bool k=true; cin>>spammers; for(int i=0; i<=spammers; i++) { peeps[31][i]=0; peeps[32][i]=0; for(int g=0; peeps[g-1][i]!='\n'; g++) { cin.get(peeps[g][i]); peeps[31][i]+=peeps[g][i]; peeps[32][i]++; } } for(int i=0; i<=spammers-1; i++) { for(int g=i+1; g<=spammers; g++) { if(peeps[31][i]==peeps[31][g] && peeps[32][i]==peeps[32][g] && peeps[31][g]!=-1) { if(k==true) { peeps[31][g]=-1; for(int y=0; peeps[y-1][g]!='\n'; y++) { cout<<peeps[y][g]; } k=false; } else { peeps[31][g]=-1; } } } k=true; } system("PAUSE"); return EXIT_SUCCESS; } Any ideas why it crashes? Sorry, your code is kind of too obfuscated for lazy me, but I would believe that you've really got access violation in your program. If you're curious, replace all arrays with vectors and use range checking access via "at". using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace _1788 { class Program { static void Main(string[] args) { string[] input = Console.ReadLine().Split(' '); int n = int.Parse(input[0]); int m = int.Parse(input[1]); int[] g = new int[n]; int[] b = new int[m]; input = Console.ReadLine().Split(' '); for (int i = 0; i < n; i++) { g[i] = int.Parse(input[i]); } input = Console.ReadLine().Split(' '); for (int i = 0; i < m; i++) { b[i] = int.Parse(input[i]); } int res = int.MaxValue; Array.Sort(g); Array.Sort(b); int ans = 0; if (n>=m) { for (int i = 0; i < n-m; i++) { ans += g[i]; } Console.WriteLine(ans); return; }
for (int i = 0; i <= n; i++) { ans = 0; for (int j = 0; j < m-i; j++) { ans += b[i] * i; } for (int q = 0; q < n-i; q++) { ans += g[q]; } res = Math.Min(res, ans); } Console.WriteLine(res); Console.ReadLine(); } } } Edited by author 15.05.2012 20:33 2 5 100 100 1 1 1 1 1 ans: 6 i passed this test corectly, but still have WA16 2 5 100 100 1 2 3 4 5 ans: 12
just stupid bug, if you will got AC, remove your code from forum )) Edited by author 19.05.2012 02:24 you should change >ans += b[i] * i; to >abs += b[j] * i; because when i=n you skip the cheapest elements from b[m]; Edited by author 11.07.2012 04:03 just wanted to thank the author Please give me this test. Try these tests: 1 5 3 -> 4 0 2 3 3 -> 6 2 Edited by author 09.07.2012 22:15 can it be solved with backtracking? but i think recursion depth will exceed memory and also lime will not pass, right? [code deleted] Edited by moderator 20.11.2019 00:14 Because you need print only answer, without other text like "Number of groups: " I couldn't understand the statements. You're supposed to see if either the next or previous tickets were lucky. For example, if it was 000001, then the previous ticket (000000) would have been lucky and you should output "Yes". my programm return "1 2 3 4 5 6 7 8 9 10 11 12 14 13 15 16" in the first test, but i have wa #1??? why??? You have "14 13" not "13 14". I'm pretty sure that's what's wrong. Good luck! maybe 11 can you give me your answer for 11th?? :( VF_1000000000(11) = 75501 I had WA#8 and miraculously found a bug in my backtracking&memorization with the following test: > 50 2 > 99 100 > 98 99 The problem was in printing a solution, when N tasks for the first round are prepared properly, but the other N are contradictory (because I quit from backtracking too soon). We probably wouldn't have experienced this if we had written a proper DP solution instead. :-) Edited by author 08.07.2012 18:21 Why is it tagged as 'data structures'? I used only one array to store the input. Edited by author 08.07.2012 15:47 ? same here. u seem have a correction for it. Can you tell me what's it ? :D My solution is based on the concept of strong connectivity. I find connected components of the graph, then I print those jedis, that belong to the non-dominated component. It is npt very quick, but it works. I don't know, how BFS can help with this problem. Any explanation will be very much appreciated. (de bene esse: my e-mail is akhmed[at]astranet[dot]ru). for each start among knights mark all that can be reached from start thru winning if all are marked then print start's name To test your speed, you can use the following perl script to generate input: $n = 200; print "$n\n"; for(1..$n){ print "J$_"; print ' ', int(rand()*100000) for 1..3; print "\n" } O(N*log(N)) solution exists :) Give some some tests ,please Edited by author 07.07.2012 22:30 program kamni; var n, i, k, min, v,a,b: integer; m: array[1..1000] of int64; begin readln(n); for i := 1 to n do begin read (m[i]); end; for i := 1 to n - 1 do begin min := i; for k := i + 1 to n do if m[min] < m[k] then min := k; v := m[min]; m[min] := m[i]; m[i] := v; end; a:=0; b:=0; for i:=1 to n do if a-b<=0 then a:=a+m[i] else b:=b+m[i]; begin writeln(a-b); end; end. 6 1 4 5 6 7 9 why 2? 9+7=16 и 1+4+5+6=16 o, senk you!) Edited by author 02.03.2012 01:01 I got about 20 WAs on #11, can anyone tell me any trick on this test? I didn't use biginteger, I checked every * operator, and I'm sure it wasn't overflow. All right...I make a mistake....-_____- do you have any idea about this test? import java.util.*; public class main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int k = in.nextInt(); int a = n / k; // Считаем колличество ПОЛНЫХ партий int b = n % k; // Определяем наличие НЕ ПОЛНОЙ партии if (b > 0) { a += 1; // В случае наличия НЕ ПОЛНОЙ партии увеличиваем общее число партий на 1 } System.out.println(2 * a); // Умножаем колличество партий на 2 минуты } } potomu chto mozhno i mensh i bolshe sdelat! A etot code ne raboteat! Ya sam vpervye tak napisal В самом примере неверный ответ. В примере 3 бифштекса, к-во бифштексов на сковороде 2. Ответ: 3. Полный бред! Ответ не может быть непарное число, так как 1 заход жарки = 2 минуты. При умножении на 2 всегда будет парное число. А верный ответ в примере должен быть 4. I заход. 2 бифштекса за 2 минуты; II заход. 1 бифштекс за 2 минуты. Не будем же мы есть бифштекс, прожареный с одной стороны? Результат 2минуты + 2 минуты = 4. FilEV, you are not right. It is a right answer in sample. You just not understand, how to do it in 3 minutes :) А теперь по-русски, потому как не знаю как это сказать по-английски :) Рассмотрим пример. Требуется прожарить 3 бифштекса на сковородке, которая вмещает 2 бифштекса. Ложим сначала 2 бифштекса и жарим их одну минуту. Один бифштекс переворачиваем, другой убираем, ложим третий, жарим одну минуту. Теперь убираем первый, уже прожарившийся, переворачиваем третий, и возвращаем на сковородку второй и жарим ещё минуту. Итого 3 минуты, все бифштексы готовы. Вопрос в том, как использовать ресурсы сковородки. В моём объяснении сковородка постоянно была полностью заполнена. Если сначала полностью прожарить два бифштекса,убрать их и положить третий, то сковородка будет наполовину пуста, т.е. будет работать не в полную мощность - получится, что мы тратим её ресурсы зря. Только и всего. А вообще, раз 3 бифштекса, то значит требуется 6 бифштексо-минут; сковородка за минуту выдаёт 2 бифштексо-минуты, а значит, ответ 3 минуты. Andrew Sboev, действительно. Чувствую себя бараном. Нешироко взглянул на ситуацию, впрочем это моя распространенная проблема. Теперь раз 20 подумаю, прежде писать что-либо. uses SysUtils; var a,numb,prov:string; i:integer; begin //a:='1427 0'+#13+#10+' '+'876652098643267843'+#13+'5276538'+#10+' '; readln(a); for i := length(a) downto 1 do begin prov:=copy(a,i,1); if (prov=#13) or (prov=#10) or (prov=#32) then begin if numb<>'' then writeln(FormatFloat('0.0000',(sqrt(strtofloat(numb))))); numb:=''; end else numb:=prov+numb; end; writeln(FormatFloat('0.0000',(sqrt(strtofloat(numb))))); readln; end. Edited by author 05.07.2012 21:19 How this can work on your computer??? When you do readln(a), the only thing you get in string a is the first line of input. So, you don't process anything behind that. Also, if the last line of input ends with line break, I presume your code will print additional rubbish at the end of output. Read the FAQ and study how to input data in different formats (in this problem it is better to use extended or how long real is called in Pascal?) Edited by author 05.07.2012 23:06 |
|