|
|
Common BoardTo play optimally, both players would first move towards each other and then from the point of their intersection they will take all the numbers from that point to their nearest boundaries. Let Player 1 start from X and Player 2 start from Y. Then, if (X < Y), player 1 will take all the numbers from A[1] to A[X] and player 2 will take all the numbers from A[Y] to A[N] and also player 1 will take the numbers from A[X] to A[(X+Y)/2] and player 2 will take the numbers from A[(X+Y)/2+1] to A[Y]. if (X > Y) same as above but now player 1 will work from X to N and player 2 will work from 1 to Y. if (X == Y), calculate the sum from A[1] to A[X-1] and another sum from A[X+1] to A[N], add A[X] to the greater sum and give it to player 1. here is my code import java.io.PrintWriter; import java.util.*; public class Problem1100 { public static class Busket extends LinkedList<Long>{} public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int times = in.nextInt(); Busket[] list = new Busket[100]; long id =0; int score =0; for(int i =0;i<times;i++){ id = in.nextLong(); score = in.nextInt(); boolean insert=false; if(list[score]==null){ Busket busket = new Busket(); busket.add(id); list[score]=busket; } else{ list[score].add(id); } } StringBuffer result = new StringBuffer(); for(int i = list.length-1;i>=0; i--){ Busket busket =list[i]; if(busket!=null) for(Long mId: busket) { result.append(mId); result.append(" "); result.append(i); result.append("\n"); } } out.println(result.toString()); out.flush(); } } Edited by author 24.05.2016 13:57 Edited by author 24.05.2016 14:01 Edited by author 24.05.2016 14:09 Edited by author 24.05.2016 14:11 new Busket[100] means indices 0..99. Use [101] for 0..100 indices. Edited by author 24.05.2016 14:33 This problem is very easy, try to solve it when 4 * (n-1) + 1 points are given. Another hint: imagine if you got n points and you could cheat and make them all respect each other by stretching or compressing the coordinate grid (while keeping the points static); what would be the simplest way to transform the grid? In this problem you can't cheat like that, but on the other hand you only need to have n/5 points work together. Can somebody give some tests? Thank you.. input 0 30 -25.9807621135 -15 25.9807621135 -15 output -8.2902573694809689e-012 -4.7855053253442748e-012 8.0829037686437069 13.999999999999361 16.165807537287968 -3.1885605267234496e-013 -1.6580514738954005e-011 -29.999999999980858 -25.980762113541445 15.000000000004786 25.980762113533153 15.000000000019146 input 0 0 5 8.6602540378443864676372317075294 10 0 output 5 2.8867513459481291 3.9106836025229588 0.99999999999999989 6.0893163974770417 0.99999999999999989 10 5.7735026918962582 0 5.7735026918962582 5 -2.8867513459481291 WA1 could also be too low output precision! If you have TLE on 9 and you are using Palindomic tree, You should write cin/cout with "ios_base::sync_with_stdio (false);" instead of scanf/printf cin/cout with "ios_base::sync_with_stdio (false);" got TLE on 9 for me. But these lines are faster: scanf("%s", input); ..... puts(answer); where input and answer are char arrays. Give some tests. UP! Can someone explain why it happened? import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Lift { public static final float LIFT_DELAY = 15; public static final float PETYA_DELAY = 5; public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(reader.readLine()); float petyaFloor = Float.parseFloat(st.nextToken()); float liftFloor = Float.parseFloat(st.nextToken()); float petyaSpeed = Float.parseFloat(st.nextToken()); float liftSpeed = Float.parseFloat(st.nextToken()); float timeByFootToTheFirstFloor = ((petyaFloor - 1) * petyaSpeed); //время, если идти до 1го этажа пешком float firstLiftDescentTime = ((liftFloor - 1) * liftSpeed) + LIFT_DELAY; //время, затраченное лифтом при спуске и простое на 1м этаже Float numOfFloorToGoByFoot = firstLiftDescentTime / petyaSpeed; //количество этажей, которые может успеть пройти Петя за время спуска лифта int numOfFloors = numOfFloorToGoByFoot.intValue(); //см. предыдущее Float numOfSeekingFloor = petyaFloor - numOfFloors; //искомый этаж float timeLiftWithPetya = (((numOfSearchingFloor - 1) * liftSpeed) * 2) + firstLiftDescentTime + PETYA_DELAY; //время на спуск, подъём к Пете на новый этаж и спуск с ним до 1го этажа if (timeByFootToTheFirstFloor < timeLiftWithPetya) { System.out.println("1"); } else if (timeByFootToTheFirstFloor == timeLiftWithPetya) { String s = numOfSearchingFloor.longValue() + ""; System.out.println(s); } else { String s = numOfSearchingFloor.longValue() + ""; System.out.println(s); } } } 50 49 0.99 0.28 Answer 21, yours 22. I've rounded up this float, now I get the same answer as you, but it still gives me WA#3 :( Could you please give me one more hint? Edited by author 23.05.2016 14:07 Change while (getline(cin, s)) { //... } to while (getline(cin, s)) { if (s == "") continue; //... } Test case: goto Main END: end MAIN: print 1 if 1 == 2 goto end print 2 if 1 == 2 goto end Edited by author 22.05.2016 14:25 What is real TL? In statements it is 0.5s, but in solutions rating there are solutions which passed with time bigger than 0.5s. For some tasks, they had a bigger time limit before, but after it changed, old solutions might have not been rejudged for whatever reasons. !!Please be aware of fmt.Scanf poor performance!! I did everything to test it on Timus and feel so sorry for it. My code logic is ok except this! It took a day to figure out. I got AC with FreePascal before, and now Golang. So my advice is: read all input first using bufio and ioutil like this: input = bufio.NewReader(os.Stdin) output = bufio.NewWriter(os.Stdout) _wholeText, _ := ioutil.ReadAll(input) numbers := strings.Fields(string(_wholeText)) I solved this problem by used recursion without DP. I'm trying to find a solution using DP, I found a public solution using DP + Bitmark, but it's hard to me to understand. How can I solve this problem using DP without Bitmark??? All symbols are important, not "only printable". Pay attention to EOL, EOF, and symbols with codes below 32. what is EOL, EOF symbols??????? "end of line" (ascii 13 and 10) and "end of file" here is my code: I don't know wht's the error ,anyone help me? Const u=['a'..'z']+['A'..'Z']; Var s:string; ch:char; i:integer; Begin read(ch); while not eof do begin s:=''; while (ch in u) and (ord(ch)<>26) do begin s:=s+ch; read(ch); end; for i:=length(s) downto 1 do write(s[i]); while (not (ch in u)) and (ord(ch)<>26) do begin write(ch); read(ch); end; end; End. check whether you output EOF. If you output it you will get WA. I got really angry when I understood that my program didn't work, because I print EOF!!!! #include<iostream> #include<algorithm> #include<string> using namespace std; int main() { string text; while(getline(cin,text)) { string s=""; for(int i=0;i<text.size();i++) if(('a'<=text[i]&&text[i]<='z') ||('A'<=text[i]&&text[i]<='Z')) s.push_back(text[i]); else { reverse(s.begin(),s.end()); cout<<s; s=""; cout<<text[i]; } cout<<endl; } //system("pause"); return 0; } Can anybody give some useful tests to pass test 3? And what about that situation: there are two the same cards in Dima's sleeve and there is the same card in Dima's or Sasha's set? For example: AC QH 10H JC KC 4D AC AC Is that possible? UPD: as I understood, yes... though doesn't matter, AC now. Edited by author 15.05.2016 21:18 I got a WA because I think L can be 1 thnx man .. that should help 5 years later, same trap grabbing me :( Я хочу провести своё соревнование. Как это можно сделать? Какие есть варианты проведения? Писал по адресу timus_support@acm.timus.ru, но ответа не получил. В администрации есть кто живой? Кодефорсес же есть Можете дать ссылку, где написано как провести своё соревнование в codeforces? Edited by author 13.05.2016 12:23 Edited by author 13.05.2016 12:23 Can anyone give me some test cases because I really don't know where my program is wrong ? Nevermind, this test case helped me find my mistake: "ababbaa" Me too. Thanks nice test. Is there a way to know more precisely what is going on on the test machine? I've tested my python solution on my machine on large data (N=10^6) with a lot of copying operations (geometric progression) and got answer with memory used < 64Mb. #include <iostream> using namespace std; int main() { int n; cin>>n; string s; int a=1; int counter=0; for(int i=0; i<n; i++) { cin>>s; if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==2) { a=1; counter++;} else if((s[0]=='A' || s[0]=='P' || s[0]=='R' || s[0]=='O' ) && a==3) { a=1; counter+=2;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==1){ a=2; counter++;} else if((s[0]=='B' || s[0]=='M' || s[0]=='S') && a==3){ a=2; counter++;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==1) { a=3; counter+=2;} else if((s[0]=='D' || s[0]=='G' || s[0]=='J' || s[0]=='K' || s[0]=='T' || s[0]=='W' ) && a==2) { a=3; counter++;}
} cout<<counter; system("pause"); return 0; } my code is wrong in the test 8 but i dont know the test, can you help me? |
|
|