Common Boardwhat's wrong in my code: #include <iostream> int main() { int N; std::cin >> N; int result=0; if (N=0){ std::cout << 1 << std::endl; return 0; } if (N > 0) { for (int i=2; i<=N;i++) { result+=i; } std::cout << result << std::endl; return 0; }else { for (int i=-2;i >=N;i--) { result+=i; } std::cout << result << std::endl; return 0; } return 0; } Edited by author 18.10.2013 23:00 I saw many guys got AC very fast,is there any way to work the problem out other than just find-cycle? There is a catch, you should account for three situations: 1) N > 0 2) N < 0 3) N == 0 <--- 8-D. Small assignment, but took an hour of trying. you could just come up with the relatively less error-prone solution in one line for(int i = 1; i!=N+2*(N>0)-1; i+=2*(N>0)-1) sum+=i; Edited by author 16.11.2013 15:47 I think that code is easy to understand. If you got WA, try it. #include <iostream> #include <map> using namespace std; int main() { map<char, string> m; int n; cin >> n; while (n--) { char c1, c2; cin >> c1 >> c2; m[c1].push_back(c2); } char c; cin >> c; for (int i = 0; i < m[c].size(); ++i) cout << c << m[c][i] << endl; return 0; } #include <iostream> using namespace std; int main () { short int i, n1, n2, n3; cin >> i; cin.sync(); char *name1, *name2, *name3, *name = new char[20]; n1 = n2 = n3 = 0; name1 = "Emperor Penguin"; name2 = "Macaroni Penguin"; name3 = "Little Penguin"; while (i > 0) { cin.getline(name,19); cin.sync(); switch(name[0]) { case 'E': n1++; break; case 'M': n2++; break; case 'L': n3++; break; } i--; } if (n1 > n2 && n1 > n3) printf("%s",name1); else if (n2 > n1 && n2 > n3) printf("%s",name2); else if(n3 > n1 && n3 > n2) printf("%s",name3); system("pause"); return 0; } used STL multimap and scanf,printf instead cin,cout got AC 0.5 sec ;) I think use a struct and sort in STL will be easier to code. Must add length to the final result. Solve it with brute force, afaik this problem is of NP class. import java.util.*; public class My { public static void main(String[] args) {
Scanner in = new Scanner(System.in); int a = in.nextInt();
if ((a >= 1) && (a <= 4)){ System.out.println("few"); } else if ((a >= 5) && (a <= 9)){ System.out.println("several"); } else if ((a >= 10) && (a <= 19)){ System.out.println("pack"); } else if ((a >= 20) && (a <= 49)){ System.out.println("lots"); } else if ((a >= 50) && (a <= 99)){ System.out.println("horde"); } else if ((a >= 100) && (a <= 249)){ System.out.println("throng"); } else if ((a >= 250) && (a <= 499)){ System.out.println("swarm"); } else if ((a >= 500) && (a <= 999)){ System.out.println("zounds"); } else if (a > 1000){ System.out.println("legion"); }
} } Please help me!!! Well, try these: 11 01011100000 01111011001 10 1001110000 0011111010 10 1001111110 0000011010 They should n't be impossible. Edited by author 31.08.2007 16:17 Edited by author 15.10.2013 21:28 Edited by author 15.10.2013 21:28 i guess the right way is like AAB AAB BBC Edited by author 25.01.2013 16:44 You think wrong, this example can be covered with only 2 letters. Brute force (полный перебор) method gives Time Limit Exceeded. In Java it takes 6 seconds to for parameters N=8, K=10. So the clever method (which uses recurrent calls) is the way to go. #include <iostream> #include <algorithm> using namespace std; struct cc{long x,y;}; cc a[150000]; long i,n; bool check(cc a, cc b){ if (a.y>b.y) return 1; else return 0; }; main(void){ scanf("%d",&n); for(i=0;i<n;i++) cin>>a[i].x>>a[i].y; //scanf("%d%d",&a[i].x,&a[i].y); sort(a,a+n,check); for(i=0;i<n;i++) cout<<a[i].x<<" "<<a[i].y<<endl; // printf("%d %d\n",a[i].x,a[i].y); }; I have no idea why it gives me wrong answer. can you help me?? there must be a stable sort I am also getting wrong answer on test case 4.pls help me this is my code #include<iostream> #include<algorithm> using namespace std; class node{ public: unsigned long long id; int prob; bool operator<(const node &n)const{ return (prob>n.prob); } }; int main() { int n;node *arr;int i,j; scanf("%d",&n); arr=new node[n]; for(i=0;i<n;i++){ cin>>arr[i].id>>arr[i].prob; } sort(arr,arr+n); for(i=0;i<n;i++) { cout<<arr[i].id<<" "<<arr[i].prob<<endl; } return 0; } I did what you had said Anton. I got WA, when I used sort, but AC , when stable_sort , both from algorithm from c++. Why? Edited by author 20.11.2008 17:22 I'd found a test like this. =) For test: 36 1 1 2 2 3 2 4 3 5 3 6 3 7 4 8 4 9 4 10 4 11 5 12 5 13 5 14 5 15 5 16 6 17 6 18 6 19 6 20 6 21 6 22 7 23 7 24 7 25 7 26 7 27 7 28 7 29 8 30 8 31 8 32 8 33 8 34 8 35 8 36 8 my prog, that uses just sort() gives answer 36 8 35 8 ... and it answered correct when i used stable_sort() with same compare function: 29 8 30 8 ... After that i suppose to write new compare function, using indexes struct state { int id, m, ind; // << ind is a new param }; bool compare( state a, state b ) { if ( a.m == b.m ) return a.ind < b.ind; return a.m > b.m; } So watch at the results of my work: sort() WA#4 stable_sort() AC 0.187s 1885 KB sort() + ind AC 0.218s 1897 KB So we can say, stable_sort uses equal amount of additional memory, as like we use standard sort and indexes, but at this dataset stable_sort works a little quicker! stable_sort() + ind (i made it for lulz) AC 0.203 2769 KB Still quicker, than sort! =) Counting sort AC 0.125 1233 KB ;) And after some zhest' optimizations... AC 0.062 1225 KB %) %) Thank you very much, I have used a lot of sorts but they're useless. You can tell me about the idea of stable_sort because my teacher doesn't allow me to use the library C/C++. I used counting_sort and AC, but I want to install that algorithm myselft. Please help me wy wrong#2 help me please!!! What is second test I use n/2 array and i insure that my program right, but i got WA5. please insure that's rigth test or give me it. anybody knows where i can got test? I also have problems with test #5. Can someone post some test cases? I use unsigned long datatype which enough for numbers ranging from 0 to 2^32-1, right? I also use heap and the program does not get Memory Limit Exceeded. Unfortunaly I get WA on test#5 and I don't know the reason yet. Does anyone have some nice tests for this problem? Thanks in advance. Peter I hope it will help you: 3 4294967295 4294967295 4294967295 and 4 4294967295 4294967295 4294967295 4294967295 PS 4294967295 = 2^32-1 lots of programs get WA cause overflow (-1.0), but correct answer for test #1 is 4294967295.0 Good luck! Edited by author 30.08.2006 21:02 2^31-1 = 2'147'483'647 (2^31-1) * 2 = 4'294'967'294 overflow is when you do this: [(2^31-1) + (2^31-1)] / 2 = (4'294'967'294) / 2 = 2^31-1 My program successfully passes these tests but still has WA#5 :( try this test: 66 1822588296 1499349644 1998339909 438738270 168078851 1372627910 950185897 1382051023 963930101 1831994657 1871239379 1044037823 1835050606 960512955 708338089 2003230326 1035076748 89016539 858957869 1853110619 895749309 148663460 1137471506 603327469 659851397 1213636411 1075864991 970750774 1582471369 2081718373 1883405666 1093053606 1015209628 2107379130 1789966364 1740289668 501120122 2134118210 604918626 1788007116 303708185 294840996 1477373566 1880931488 1101825197 1005585635 1068936228 786341935 305053122 709515845 1220466783 72910094 1574722146 903771479 1113070349 1613404991 1384276211 1274833854 857128720 662590071 1266344829 1996098077 1277433268 1956553751 991087736 227071513 Dear Macarie I got WA#5 too, Can you tell me your method to this question, please. thank you!I overlooked this point …… Уважаемые администраторы сайта! Подскажите, пожалуйста, что Вы собираетесь делать с посылками, которые получали AC на компиляторе Intel C++ 7, и получают Time Limit на компиляторах G++ 4.7.2 и Visual C++ 2010? У меня, например, около 4-5 таких задач было, пришлось все их перерешивать по-другому. Ведь теперь нет возможности отправить задачу на старом компиляторе. Извиняйте, но тогда нужно перетестировать посылки под Intel C++ 7 на новых компиляторах, а то результаты и рейтинг получаются НЕЧЕСТНЫМИ !!! Ведь не все перерешивают уже "сданные" задачи. Нельзя переводить старые решения на новые компиляторы, потому что половина из них не откомпилируется или станет выводить другие ответы. я пробовал интегрировать и аналитически и численно, выдает то что должен выдавать в примере, но вот AC так и нет I think description of the problem should state that "long numbers have to be used". So for this problem use long integers. I think description of the problem should state that "long numbers have to be used". So for this problem use long integers. |
|