Common BoardI thought my solution is quite "brute", are there any other solutions? And I have to say it is a really good problem for sufficient samples and a clear statement. And where is your solution? I cant ivent any tests that my solution will fail, but I have WA1! Can any body help... Give me some test! Plz... example tests 4 0110 0011 0001 1000 4 1 4 2 3 3 2 4 1 my output: No No No No 3 010 000 100 3 1 3 3 1 2 3 out: No Yes No Is it correct? Give some more tests! You should print "YES", but not "Yes"... WA 2 CODE: program china; var t:char; i,j,k:integer; a:array[1..100,1..100] of boolean; b:array[1..100] of integer; chk:array[1..100] of boolean; x,y,q,n,m:integer; procedure solve(k:integer); var i:integer; begin for i:=1 to n do begin if a[k,i] then begin if not chk[i] then begin chk[i]:=true; solve(i); end; end; end; end; begin readln(n); for i:=1 to n do begin for j:=1 to n do begin read(t); if t='0' then a[i,j]:=false else a[i,j]:=true; end; readln; end; for i:=1 to n do begin fillchar(chk,n,false); solve(i); for j:=1 to n do begin if chk[j] then b[i]:=b[i]+1; end; end; readln(q); for i:=1 to q do begin readln(x,y); if b[x]>b[y] then writeln('YES') else writeln('No'); end; end. may be this test will help you: 4 0010 0001 0100 0000 4 1 2 1 4 4 1 4 3 answer: YES YES YES No Why answer for 1 4 and 4 1 YES and what is the anwer for 4 0100 0000 0001 0000 7 1 2 2 1 3 4 4 3 3 1 1 3 3 2 Why answer for 1 4 and 4 1 YES Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". My answer for your test: YES YES YES YES YES YES YES Thank you, your answer helped me mutch! Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". Where this is written in the statement? Why can't I solve the problem this way: 1. Make transitive closure of the given graph (matrix A)using Floyd. 2. For every request (pair i j) print "YES" if A[i][j] = 1 otherwise print "No". Because you should print "No" only if nodex x and y have common predecessor. In other cases you should print "YES". Where this is written in the statement? Here: "In this case we say that the team A is stronger than the teams B and C (more formally, A is stronger than B if A has beaten B or if A has beaten a team C which is stronger than B)." Edited by author 18.10.2006 23:11 Edited by author 18.10.2006 23:114 1 anwer is No, because 1 better than 3, 3 better than 2, 2 better than 4 => 1 better than 4 8 AA BB CC DD EE FF GG HH 6 AA HIT BB IN HEAD AA HIT CC IN HEAD AA HIT DD IN HEAD AA REVIVE BB AA REVIVE CC EE REVIVE DD CORRECT AA BB CC FF DD EE GG HH I'll throw in another test for WA 44: 12 A B C D E F G H I J K L 16 A HIT B IN HEAD A REVIVE B B HIT C IN HEAD B REVIVE C D HIT E IN HEAD D REVIVE E E HIT F IN HEAD E REVIVE F G HIT H IN HEAD G REVIVE H H HIT I IN HEAD H REVIVE I J HIT K IN HEAD J REVIVE K K HIT L IN HEAD K REVIVE L FAKE Teams 3+3+3+3=12 cannot assemble into teams of 4. Same, for example, for (3+2)+(3+2)+(3+2)+(3+2)=20, etc. 100000000 10 1 5 even 6 10 even 11 18 even 19 25 even 1 8 even 16 25 even 16 40 even 9 40 odd 1000 5000 odd 1000 6000 odd -1 answer: 7 why is it 7? could you explain? I had runtime error 25, but when i surrounded sorting with try catch it accepted Any ideas why? #solution 1068 x=int(input("enter your number: ")) def factorial(x): if x>0: return x + factorial(x - 1) elif x<0: return x + factorial(x+1) if x==0: return 0 y=factorial(x) if x<0: print(y+1) else: print(y) n = int(input()) if n > 0: print(int(n*(n+1)/2)) elif n == 0: print('1') else: print(int(n*(n-1)/-2 + 1)) delete Edited by author 04.10.2020 16:38 #include<bits/stdc++.h> using namespace std; map<string,int>mp; int main() { ios_base::sync_with_stdio(false); cin.tie(0); string s; string tr="tram"; string tro="trolleybus"; string last=""; while(getline(cin,s)) { string subject=s; regex re("\\w+"); sregex_iterator next(subject.begin(), subject.end(), re); sregex_iterator end; while (next != end) { smatch match = *next; last=match.str(); if(last==tr) mp[tr]++; else if(last==tro) mp[tro]++; next++; } } if(mp[tro]>mp[tr]) cout<<"Trolleybus driver"<<endl; else if(mp[tr]>mp[tro]) cout<<"Tram driver"<<endl; else cout<<"Bus driver"<<endl; } What's wrong with test #38? I got AC with sorting but failed on majority search? I've got AC without sorting. I have failed on #38 recently on a test like: 7 4 1 1 2 1 1 3 input : 15 4 1 2 30 994 50 600 700 999 900 990 991 992 993 40 800 output : 1 50 900 993 2 600 990 40 30 700 991 800 994 999 992 input:: 9 2 1 2 3 4 5 6 7 8 9 output:: 1 6 2 7 3 8 4 9 5 9 4 100 10 1 0 999 2 999 999 1 out: 100 0 999 10 999 999 1 2 1 Edited by author 08.05.2019 13:24 Edited by author 08.05.2019 13:24 If you have WA4, try a 100x100 matrix with all 1 or with all 0. Edited by author 12.05.2019 20:53 import java.util.Scanner; public class task9 {
public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); int x = sc.nextInt(); int y = sc.nextInt(); int cl = 0; int stroka =1; int[][] mas = new int[n][m]; for(int i=0;i<n;i++){ if(stroka%2==1){ for(int j=0;j<m;j++){ mas[i][j]=cl; cl++;
} stroka++; } else{ for(int j=m-1;j>=0;j--){ mas[i][j]=cl; cl++; } stroka++; } } System.out.println(mas[x-1][y-1]);
}
} ¼script¾alert(¢1¢)¼/script¾ Edited by author 07.05.2019 14:29 Edited by author 07.05.2019 14:36 The problem is to find how many l*1 or 1*l while rectangles that do not *included* by each others. My solution is O(NlogN),but I thought there may be some solutions use only O(N) time, thank you for your sharing! Question requirements are ordered without changing order #include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int maxn = 150005; struct Node { int index; int ID; int mount; }node[maxn]; int N; bool cmp(Node &a, Node &b) { if (a.mount != b.mount) { return a.mount > b.mount; } else { return a.index < b.index; } } int main() { scanf("%d", &N); for (int i=0; i<N; i++) { scanf("%d%d", &node[i].ID, &node[i].mount); node[i].index = i; }
sort(node, node + N, cmp);
for (int i=0; i<N; i++) { printf("%d %d\n", node[i].ID, node[i].mount); } return 0; } I tried so many time until I change `#include<bits/stdc++.h>` to `#include<stdio.h>`. And then I did a small experience: for the same code, Visual C++ 2017 -- 612 KB Visual C 2017 -- 620 KB GCC 7.1 / Clang++ 4.0.1 -- 652 KB G++ 7.1 -- 700 KB Hope it helps~ #include <iostream> int main(void){ char nameOfKid[8]; int noOfLetters; std::cin >> noOfLetters; std::cin.ignore( 256, '\n') ; int cur, temp, steps, newcur; newcur = 0; cur = 0; steps= 0 ; for (int i = 0 ; i < noOfLetters; ++i){
std::cin.getline(nameOfKid, 8);
temp = static_cast<int>(nameOfKid[0]); switch(temp){ case 65: case 80: case 79: case 82: newcur = 1; break; case 66: case 77: case 83: newcur = 2; break; case 68: case 71: case 74: case 75: case 84: newcur = 3; break;
} if ((newcur!=cur) && (i!=0)){ steps = steps + ((newcur>cur) ? (newcur-cur): (cur-newcur));
} cur = newcur; } std::cout << steps; return 0; } You can store first letters with their's corresponding place like that: int m[256]; m['A'] = m['P'] = m['O'] = m['R'] = 1; m['B'] = m['M'] = m['S'] = 2; m['D'] = m['G'] = m['J'] = m['K'] = m['T'] = m['W'] = 3; #include<bits/stdc++.h> using namespace std; int main(){ map<char,int>mp; mp['A'] = 1; mp['O'] = 1; mp['R'] = 1; mp['P'] = 1; mp['B'] = 2; mp['M'] = 2; mp['S'] = 2; mp['D'] = 3; mp['G'] = 3; mp['J'] = 3; mp['K'] = 3; mp['T'] = 3; mp['W'] = 3; int n,ans=0,pre=-1; string s; cin>>n; while(n--){ cin>>s; if(pre== -1){ pre = mp[s[0]]; }else{ ans += abs(mp[s[0]] - pre); pre = mp[s[0]]; } } cout<<ans<<endl; return 0; } i also got WA#3 doing in same way. Solving the problem using the merge sort approach (counting inversions while merging subsequences - plus one inversion in a case of element from the left subseq greater than the element from the right) looks feasible (and maybe evident) to implement. But there is one caveat: it is crucial to count not only the one inversion in a case *cur_left > *cur_right, but count elements in a range [cur_left + 1, right_begin) as "inverted" too. That follows from the fact that merged subarrays are sorted in ascending order, so if we encountered the (*cur_left > *cur_right) case, then elements in a range [cur_left + 1, right_begin) satisfies that too and could be counted as inversions. Hope I stated that clearly. Edited by author 04.05.2019 18:59 Edited by author 06.05.2019 06:44 |
|