| Show all threads Hide all threads Show all messages Hide all messages | | RE - #14..(c++). because of map<string,int>? | OIdiot | 1837. Isenbaev's Number | 9 Feb 2015 07:13 | 2 | /* Machine: Class4_B2 System: Windows7 SP1 32bit */ [code deleted] Edited by moderator 19.11.2019 23:15 My bad.. I thought it only contains 100 names, but 300 in fact. | | different between undefined and 3 | amirshir | 1837. Isenbaev's Number | 9 Feb 2015 06:59 | 2 | what's different between undefined and 3? can you help me? Isenbaev -> a -> b -> c. In this chain, a is 1, b is 2 and c is 3. Obviously,there is a path from Isenbaev to c. But In this situation: Isenbaev -> a -> b. c. c isn't a teammate of anyone who is connected with Isenbaev. So, c is 'undefined'. | | Help!! WA test 9 | tinrodriguez | 1837. Isenbaev's Number | 11 Jan 2015 05:21 | 1 | | | WA testcase #1 | Manish Jangir | 1837. Isenbaev's Number | 4 Dec 2014 18:18 | 2 | i tried BFS. but WA in test #1. Can anyone suggest some test cases? Thanks.. Don't output last CRLF. Bad cheker. | | WA #11 | Alexander31 | 1837. Isenbaev's Number | 23 Aug 2014 05:41 | 1 | WA #11 Alexander31 23 Aug 2014 05:41 People, please, help me. I got WA 11. Can anybody give me test? Here is my solution: #include <iostream> #include <map> #include <queue> #include <vector> using namespace std;
int minimum(int arr[300][300], map < int, string > Num, map < string, int >L, int cur) {
int min_ = 100499;
for (int i = 0; i < cur; ++i)
if (arr[cur][i] && L[Num[i]] < min_)
min_ = L[Num[i]];
return min_; }
void Level_up(map < string, int >Nam, map < int, string > Num, map < string, int >&Lev, int sz, int arr[300][300]) {
for (int i = 0; i < sz; ++i) {
int level = Lev[Num[i]];
if (!level && Num[i] != "Isenbaev") // Если имя ещё не встречалось
Lev[Num[i]] = level = minimum(arr, Num, Lev, sz) + 1;
for (int j = 0; j < sz; ++j)
if (i != j && arr[i][j])
if ((Num[j] != "Isenbaev" && Lev[Num[j]] == 0) || Lev[Num[j]] > level + 1)
Lev[Num[j]] = level + 1;
} }
int main() {
int N;
string f;
string s;
string t;
string P = "Isenbaev";
map < string, int >Name;
map < int, string > Number;
int count = 1;
Name[P] = count++;
Number[0] = P;
int arr[300][300];
map < string, int >Level;
bool flag = false;
cin >> N;
for (int i = 0; i < N; ++i) {
cin >> f >> s >> t;
if (f == P || s == P || t == P) flag = true;
if (!Name[f])
Name[f] = count++;
if (!Name[s])
Name[s] = count++;
if (!Name[t])
Name[t] = count++;
Number[Name[f] - 1] = f;
Number[Name[s] - 1] = s;
Number[Name[t] - 1] = t;
arr[Name[f] - 1][Name[s] - 1] = arr[Name[s] - 1][Name[f] - 1] = arr[Name[f] - 1][Name[t] - 1] = arr[Name[t] - 1][Name[f] - 1] = arr[Name[s] - 1][Name[t] - 1] = arr[Name[t] - 1][Name[s] - 1] = 1;
}
Level[P] = 0;
Level_up(Name, Number, Level, count - 1, arr);
for (map < string, int >::iterator it = Level.begin(); it != Level.end(); ++it) {
if (flag || !flag && it->first != P) {
cout << it->first << " ";
if (it->first != P)
if (it->second < count)
cout << it->second << endl;
else cout << "undefined" << endl;
else cout << it->second << endl;
}
}
return 0; } Sorry, for the my code and my English. Edited by author 24.08.2014 03:07 | | Very easy & interesting problem!!! | Odilov Azimboy | 1837. Isenbaev's Number | 29 Jul 2014 16:50 | 2 | I completely agree with you! Also, it is very good for training with maps(c++)/dictionaries(python). | | no subject | Даниил | 1837. Isenbaev's Number | 28 Mar 2014 02:12 | 1 | Edited by author 28.03.2014 23:31 | | Fails with WA @ Test Case 7 | thefourtheye | 1837. Isenbaev's Number | 12 Dec 2013 08:10 | 2 | I think we are missing something which is quite common in this case. http://ideone.com/XHozKe Can someone throw some ideas, why this fails at test case 7? ___Test 13 Fominykh Isenbaev BBB BBB CCC AAA Ayzenshteyn Oparin Samsonov Ayzenshteyn Chevdar Samsonov Dublennykh Fominykh Ivankov Burmistrov Dublennykh Kurpilyanskiy Cormen Leiserson Rivest Oparin AA AAA Isenbaev Oparin Toropov AA DD PP PP QQ RR RR SS TT TT Toropov Oparin ____correct answer: AA 2 AAA 2 Ayzenshteyn 2 BBB 1 Burmistrov 3 CCC 2 Chevdar 3 Cormen undefined DD 3 Dublennykh 2 Fominykh 1 Isenbaev 0 Ivankov 2 Kurpilyanskiy 3 Leiserson undefined Oparin 1 PP 3 QQ 4 RR 3 Rivest undefined SS 3 Samsonov 2 TT 2 Toropov 1 | | Please, suggest cases to pass test #7 | Megakrit | 1837. Isenbaev's Number | 8 Nov 2013 14:39 | 2 | Found. If someone will have the same issue, try this input: 3 Isenbaev A B A B C A Q W Edited by author 25.01.2013 23:37 Edited by author 25.01.2013 23:37 A 1 B 1 C 2 Isenbaev 0 Q 2 W 2 But i still #WA7 | | Ошибка WA #1 | Adam | 1837. Isenbaev's Number | 31 Oct 2013 16:35 | 1 | У меня все работает с разными данными. Мне кажется я не правильно поток ввода установил. Здесь нужно использовать cin? | | test 7 ??? | 2chik | 1837. Isenbaev's Number | 4 Oct 2013 12:02 | 1 | | | test 3 wrong. WHY? | bahasdu | 1837. Isenbaev's Number | 25 Jun 2013 19:22 | 4 | package problemsPackage; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.StringTokenizer; public class IsenbayevNumbers { public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int numberOfTeams = Integer.parseInt(in.readLine()); // Node containing Names of progers in team LinkedList<String[]> teamsList = new LinkedList<String[]>(); LinkedList<String> uniqueParticipantsName = new LinkedList<String>();
while (numberOfTeams != 0) { StringTokenizer tokenizer = new StringTokenizer(in.readLine(), " "); String members[] = new String[3]; int i = 0; while (tokenizer.hasMoreTokens()) { members[i] = tokenizer.nextToken(); addToList(uniqueParticipantsName, members[i]); i++; } teamsList.add(members); numberOfTeams--; } int array[][] = new int[uniqueParticipantsName.size()][uniqueParticipantsName.size()]; fillArray(array,uniqueParticipantsName,teamsList); int participants = uniqueParticipantsName.size(); int esenId = getIndex("Isenbaev", uniqueParticipantsName);
int[] tentativeDistances = new int[participants]; LinkedList<Integer>unvisitedNodes = new LinkedList<Integer>(); for(int i=0;i<participants;i++){ unvisitedNodes.add(i); if(i==esenId) tentativeDistances[i]=0; else tentativeDistances[i]=4000; }
while(unvisitedNodes.size()!=0){ int node = getCurrentNode(tentativeDistances,unvisitedNodes); processNode(node,tentativeDistances,unvisitedNodes,array); } String names[] = new String[uniqueParticipantsName.size()]; for(int i=0;i<uniqueParticipantsName.size();i++){ names[i]=uniqueParticipantsName.get(i); }
java.util.Arrays.sort(names);
for(int i=0;i<names.length;i++){ int index = getIndex(names[i], uniqueParticipantsName); int distance = tentativeDistances[index]; if(distance!=4000) System.out.print(names[i]+" "+distance+"\n"); else System.out.print(names[i]+" undefined\n"); } }
private static void processNode(int node, int[] tentativeDistances, LinkedList<Integer> unvisitedNodes, int[][] array) {
LinkedList<Integer>neighbors = new LinkedList<Integer>(); for(int j=0;j<array.length;j++){ if(node!=j) if(array[node][j]==1) neighbors.add(j); }
for(int i=0;i<neighbors.size();i++){ if(tentativeDistances[neighbors.get(i)]>tentativeDistances[node]+1) tentativeDistances[neighbors.get(i)]=tentativeDistances[node]+1; }
for(int i=0;i<unvisitedNodes.size();i++){ if(unvisitedNodes.get(i)==node){ unvisitedNodes.remove(i); break; } } } private static int getCurrentNode(int[] tentativeDistances, LinkedList<Integer> unvisitedNodes) { int minimum=10000; int index=0; for(int i=0;i<unvisitedNodes.size();i++){ if(tentativeDistances[unvisitedNodes.get(i)]<minimum){ minimum=tentativeDistances[unvisitedNodes.get(i)]; index=unvisitedNodes.get(i); } } return index; } /** * Fill twodimensional array * @param array * @param uniqueParticipantsName * @param teamsList */ private static void fillArray(int[][] array, LinkedList<String> uniqueParticipantsName, LinkedList<String[]> teamsList) { for(int i=0;i<uniqueParticipantsName.size();i++){ String name = uniqueParticipantsName.get(i); for(int j=0;j<teamsList.size();j++){ boolean exist=false; if(teamsList.get(j)[0].equalsIgnoreCase(name) || teamsList.get(j)[1].equalsIgnoreCase(name) || teamsList.get(j)[2].equalsIgnoreCase(name)) exist=true; if(exist){ if(!teamsList.get(j)[0].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[0], uniqueParticipantsName)]=1; if(!teamsList.get(j)[1].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[1], uniqueParticipantsName)]=1; if(!teamsList.get(j)[2].equalsIgnoreCase(name)) array[getIndex(name, uniqueParticipantsName)][getIndex(teamsList.get(j)[2], uniqueParticipantsName)]=1; } } } }
/** * Index of name in list. * @param name * @param uniqueParticipantsName * @return */ private static int getIndex(String name,LinkedList<String> uniqueParticipantsName){ int index=0; for(int i=0;i<uniqueParticipantsName.size();i++){ if(uniqueParticipantsName.get(i).equalsIgnoreCase(name)){ index=i; break; } } return index; }
/** * Store unique participant names into list * @param uniqueParticipantsName * @param string */ private static void addToList(LinkedList<String> uniqueParticipantsName, String string) { boolean exist = false; for (int i = 0; i < uniqueParticipantsName.size(); i++) { if (uniqueParticipantsName.get(i).equalsIgnoreCase(string)) { exist = true; break; } } if (!exist) uniqueParticipantsName.add(string); }
} Edited by author 22.02.2012 14:51 Try this test: 1 a b c Answer is a undefined b undefined c undefined | | WA #17 | Pastafarianist | 1837. Isenbaev's Number | 25 Jun 2013 19:19 | 5 | WA #17 Pastafarianist 11 Nov 2011 03:26 Any suggestions please? I'm a complete newbie at graph theory, so I guess this is something really stupid. Solved it. It wasn't actually a WA but a RT. The point is, #17 seems to contain 300 names with no Isenbaev. Thus, if you always give some fixed ID (say, zero) while giving other people other IDs, you will have an "index out of bounds" exception. My program caught that exception, printed stack trace (as you might have already guessed, my program is in Java) and exited with exit code 9000. Since stack trace is printed in stdout, Timus's checking system couldn't parse that output which resulted in WA. *if you always give HIM some fixed ID, of course Thank you very much.I got AC.>-< because, array need more than 300!! | | WA #5 | boades | 1837. Isenbaev's Number | 24 Apr 2013 18:46 | 2 | WA #5 boades 22 Apr 2013 20:11 Try it in this cases: 1. Only one team. 2. No Isenbaev at all. | | What is the answer for the such test case | Megakrit | 1837. Isenbaev's Number | 11 Feb 2013 21:46 | 2 | e.g. the input is (if I'm not wrong it's valid input): 3 Isenbaev A B A A A B B B What is the correct answer? My AC Solution's output: =============== A 1 B 1 Isenbaev 0 =============== | | Access violation N 3 | Lord_F | 1837. Isenbaev's Number | 11 Feb 2013 21:45 | 2 | #include <cstdio> #include <deque> #include <queue> #include <vector> #include <string> #include <set> #include <stack> #include <algorithm> #include <cmath> #include <iostream> #include <fstream> #include <climits> #include <cfloat> #include <map> #include <cstring> #define FOR(i,s,e) for(long i = s; i < e; ++i) #define FORD(i,e,s) for(long i =e-1; i>=s; --i) #define read(a) scanf("%ld",&a); #define readf(a) scanf("%lf",&a); #define read2(a,b) scanf("%ld %ld",&a,&b) #define read2f(a,b) scanf("%lf %lf",&a,&b) #define write(a) printf("%ld ",a); #define writef(a) printf("%lf ",a); #define write2(a,b) printf("%ld %ld ",a,b) #define write2f(a,b) printf("%lf %lf ",a,b) #define writeln(a) printf("%ld\n",a); #define writelnf(a) printf("%lf\n",a); #define writeln2(a,b) printf("%ld %ld\n",a,b) #define writeln2f(a,b) printf("%lf %lf\n",a,b) #define nln printf("\n") #define elif else if #define MOD 1000007 #define EPS 1e-9 #define INF 2117117117 #define mp(a,b) make_pair(a,b) #define dist(x1,y1,x2,y2) sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)) #define pb(a) push_back(a) using namespace std; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); long n; read(n); scanf("\n"); map<string, long> m; vector<long> g[318]; long c=0; string s1,s2,s3; FOR(i,0,n) { getline(cin,s1,' '); if (m.find(s1)==m.end()) m.insert(mp(s1,c++)); getline(cin,s2,' '); if (m.find(s2)==m.end()) m.insert(mp(s2,c++)); getline(cin,s3,'\n'); if (m.find(s3)==m.end()) m.insert(mp(s3,c++)); long a=m.find(s1)->second,b=m.find(s2)->second,c=m.find(s3)->second; g[a].pb(b); g[a].pb(c); g[b].pb(a); g[b].pb(c); g[c].pb(a); g[c].pb(b); } long d[318]; FOR(i,0,c) d[i]=-1; long s = m.find("Isenbaev")->second; d[s]=0; queue<long> q; q.push(s); long v; while (!q.empty()) { v=q.front(); q.pop(); FOR(i,0,g[v].size()) { if (d[g[v][i]]==-1) { d[g[v][i]]=d[v]+1; q.push(g[v][i]); } } } map<string, long>::iterator it; for( it = m.begin(); it != m.end(); ++it) { printf("%s ",it->first.c_str()); if (d[it->second]==-1) printf("undefined"); else write(d[it->second]); nln; } return 0; } Why?? Oh, I see now, there is no Isenbaev in the 3rd test, so all people are undefined. | | Please help with DFS. | freelife | 1837. Isenbaev's Number | 10 Feb 2013 03:12 | 1 | What is the true way to change k-(needed numbers) http://pastebin.com/f27Pt0HC - code #include <iostream>; #include <map>; #include <string>; using namespace std; // dfs( копия матрицы, кол-во вершин, указатель на юзет, в который будут добавлятся числа Исенбаева, проверяемое ребро, число Исенбаева в данный момент) int dfs(int **gr, int n, int *&q, int v, int k) { for(int i=0;i<n;i++) if ( (gr[v][i]==-1)&&(q[i]==1000) )//если из v в i есть путь и если i не обойдена { q[i]=min(k,q[i]);//чтобы избавится от 1000 dfs(gr,n,q,i,k+1); } return 1; } int main() { int x,i,j,m,n; map<string,int> a; n=0; cin>>m; int **gr=new int*[3*m]; //матрица смежности for(int i=0;i<3*m;i++) gr[i]=new int[3*m]; string s1,s2,s3; for(int i=0; i<m; i++)//ввод фамилий по 3 в строке { cin>>s1>>s2>>s3; if (a[s1]==0) a[s1]=++n; if (a[s2]==0) a[s2]=++n; if (a[s3]==0) a[s3]=++n; gr[ a[s1] ] [ a[s2] ] =-1; gr[ a[s2] ] [ a[s1] ] =-1; gr[ a[s3] ] [ a[s1] ] =-1; gr[ a[s1] ] [ a[s3] ] =-1; gr[ a[s3] ] [ a[s2] ] =-1; gr[ a[s2] ] [ a[s3] ] =-1; }; int k=1; x=a["Isenbaev"]; int *used=new int[n]; for(int i=0;i<n;used[i++]=1000); int *&q=used; cout<<dfs(gr,n,used,x,1); i=0; used[x]=0; for(map<string,int>::const_iterator x=a.begin();x!=a.end();++x,i++) if(used[i]<1000) cout<<x->first<<' '<<used[i]<<endl; else cout<<x->first<<" undefined"<<endl; delete gr,used; return 0; } | | please give me test 4!!!!! | [TH0112]_o.o | 1837. Isenbaev's Number | 19 Dec 2012 04:15 | 1 | | | wa test 4? | [TH0112]_o.o | 1837. Isenbaev's Number | 19 Dec 2012 04:02 | 1 | Edited by author 19.12.2012 04:05 wrong test 4? 1837, why? Edited by author 19.12.2012 04:06 Edited by author 19.12.2012 04:06 Edited by author 19.12.2012 04:06 Edited by author 19.12.2012 04:07 Edited by author 19.12.2012 04:10 | | Why WA#1? | S.Spooky | 1837. Isenbaev's Number | 18 Dec 2012 22:54 | 3 | I can't realize what my problem is! #1 must be the simplest test case ( or the sample given ) but I can't see anything in my code that seems to be wrong... can YOU help me? I also have a WA #1 Did you find the problem? my problem is using fflush(stdin) after cin>>n ;(n= number of team), When I delete "fflush(stdin);" , I would pass #1. But I have problem with #9. Haha... |
|
|