Common Boardinput: 5 10 0 output: 3 4 what is wrong? #include<stdio.h> #include<string.h> int comp(char *pen,char *peng) { int i; for(i=0;i<strlen(pen);i++) if(pen[i]!=peng[i]) return 0; return 1; } int main() { int i,a=0,b=0,c=0,n; char pen[3][10]={"Emperor","Little","Macaroni"},peng[20]; scanf("%d",&n); for(i=0;i<n;i++) { fflush(stdin); gets(peng); if(comp(pen[0],peng)) ++a; if(comp(pen[1],peng)) ++b; if(comp(pen[2],peng)) ++c; } if(a>b&&a>c) printf("Emperor Penguin"); if(b>a&&b>c) printf("Little Penguin"); if(c>b&&c>a) printf("Macaroni Penguin"); return 0; } figured out, you need to clear the buffer perverted by scanf ("% * [^ \ n] "); and used to enter the scanf ("% s ", peng); Dear admins, My JUDGE_IDs: 146419HS, 146556GN. Please remove me one of them. And tell me about ID, which I stayed. leofun01@hotmail.com #include <stdio.h> int main(){ long long int t; scanf("%lld", &t); printf("%lld\n%lld", t*t, t); return 0; } AC with MS VC, but WA 1 with GCC. Can anybody explain me what's wrong with my code? u should use %i64d instead %lld with GCC ;) Edited by author 12.07.2013 19:50 #include <iostream> #include <cstdlib> #include <stdio.h> //#pragma comment(linker, "/STACK:16777216")
using namespace std; int flag=0; int flag1=0; char *a = new char [10000001]; int f(int pos,int flag,int n){ int l=0; if ((pos==n+1) && (flag==1)) {std::cout<<"YES"<<endl; flag1=1; return 0;} if ((pos==n+1) && (flag==0)) {} else if (pos<=n){ {if ((a[pos]=='o') && (a[pos+1]=='u') && (a[pos+2]=='t') && (a[pos+3]=='p') && (a[pos+4]=='u') && (a[pos+5]=='t')) {f(pos+6,1,n);l=1;} if ((a[pos]=='i') && (a[pos+1]=='n') && (a[pos+2]=='p') && (a[pos+3]=='u') && (a[pos+4]=='t')) {f(pos+5,1,n);l=1;} if ((a[pos]=='p') && (a[pos+1]=='u') && (a[pos+2]=='t') && (a[pos+3]=='o') && (a[pos+4]=='n')) {f(pos+5,1,n);l=1;} if ((a[pos]=='o') && (a[pos+1]=='u') && (a[pos+2]=='t')) {f(pos+3,1,n);l=1;} if ((a[pos]=='o') && (a[pos+1]=='n') && (a[pos+2]=='e')) {f(pos+3,1,n);l=1;} if ((a[pos]=='i') && (a[pos+1]=='n')) {f(pos+2,1,n);l=1;} if (l==0) {} }} }
int main() { int k=0,n=0,j=0; int i=0; std::cin>>k; char c; for (j=1;j<=k+1;j++) { i=0; flag1=0; while (((c = getchar()) != '\n') ) {a[i]=c;i++;} n=i-1;
if (n>0) { f(0,0,n); if (flag1==0) std::cout<<"NO"<<endl;}
}
} Edited by author 11.07.2013 23:48 Edited by author 11.07.2013 23:49 #include <iostream> #include <cstdlib> #include <stdio.h> #include <string> #include <cstring> using namespace std; int flag=0; int flag1=0; char *a = new char [10000000]; int main() { int k=0,n=0,j=0,l=0; int i=0,pos=0; std::cin>>k; char c; for (j=1;j<=k+1;j++) { i=0; l=0; gets(a); n=strlen(a);n--;
if (n>0){
pos=n;
while (pos>0){ if ((a[pos]=='t') && (a[pos-1]=='u') && (a[pos-2]=='p') && (a[pos-3]=='t') && (a[pos-4]=='u') && (a[pos-5]=='o')) {l=1;pos=pos-6;} if ((a[pos]=='t') && (a[pos-1]=='u') && (a[pos-2]=='p') && (a[pos-3]=='n') && (a[pos-4]=='i')) {l=1;pos=pos-5;} if ((a[pos]=='n') && (a[pos-1]=='o') && (a[pos-2]=='t') && (a[pos-3]=='u') && (a[pos-4]=='p')) {l=1;pos=pos-5;} if ((a[pos]=='t') && (a[pos-1]=='u') && (a[pos-2]=='o')) {l=1;pos=pos-3;} if ((a[pos]=='e') && (a[pos-1]=='n') && (a[pos-2]=='o')) {l=1;pos=pos-3;} if ((a[pos]=='n') && (a[pos-1]=='i')) {l=1;pos=pos-2;} if (l==0) {break;} } if (l==1) std::cout<<"YES"; else std::cout<<"NO"; }}
delete [] a; } Don't read the whole file (and even line!) into memory - each time you need only the last and previous words - so, this problem is solvable in O(1) memory 4 3 - 4 3 3 - 2 Is it not true 4 3 - 6, 3 3 - 3? Read the statement carefully: M and N are the number of streets, which encompass M-1 and N-1 blocks. I have WA2, but I don't know why. What a trick in test 2? Or can you give me some tricky tests? My mistake. I forgot to comment out the line. заменил std::ends на ' ' и сразу "Accepted" ну как так можно? Edited by author 11.07.2013 17:18 what is it? plz // Deadly Accuracy.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <algorithm> using namespace std; int n=0,p=0; int counter[1000001]={0}; int main() { cin>>n>>p; int a=0; int maxCoins=0; int timeOfAttack=0;
for (int i=0;i<n;i++){ cin>>a; counter[a]++; }
int tempR=0; int tempCoin=0; for (int i=1;i<=p && i<=1000000;i++) { if (i*counter[i]<=p && counter[i]!=0) {
if (i*(tempCoin+counter[i])>p) { if (tempR<=p && tempCoin!=0 &&tempR !=0){ timeOfAttack++; maxCoins+=tempCoin; } tempCoin=counter[i];
} else tempCoin+=counter[i]; tempR=i*tempCoin; } } if (tempR<=p && tempCoin!=0 &&tempR !=0) { timeOfAttack++; maxCoins+=tempCoin; }
cout<<maxCoins<<' '<<timeOfAttack<<endl; cin>>a; return 0; } HA Edited by author 09.07.2013 17:16 Edited by author 09.07.2013 17:16 Edited by author 09.07.2013 17:17 Edited by author 09.07.2013 17:19 Edited by author 09.07.2013 16:05 Hello Edited by author 09.07.2013 15:24 Edited by author 09.07.2013 17:20 Last symbol of first string is space. My solution: http://pastebin.com/BVfebbpv I used such algorithm: 1) sort of each point (it seems to work correctly on tests with same coordinates) 2) walk through sorted array of points, making dp on every segment with two variables (maxi and maxv) to indicate maximum value we can reach in this segment and id of inside segment, corresponding to this maaximal value I tried almost all tests from topics and lots, invented by myself and can't get what's wrong with my solution. Try 3 1 6 3 9 3 5 try this 8 1 10 2 3 4 5 6 7 8 9 20 30 21 29 22 28 answer 3 8 7 6 I also had WA#3, but this test is AC. My solution used BFS. Please, help me! Thanks! #pragma comment(linker,"/STACK:8000000") #include <stdio.h> int loading(int &N,int** (&M)){ int *Left,*Right; scanf("%d",&N); if(N==0) {printf("%d",0); return -1;} Left=new int[N]; Right=new int[N]; int tmpL,tmpR; for(int i=0;i<N;++i) {scanf("%d %d",&tmpL,&tmpR); /*if(tmpR<tmpL) {int tmp=tmpR; tmpR=tmpL; tmpL=tmp;}*/ Left[i]=tmpL; Right[i]=tmpR;} M=new int*[N]; for(int i=0;i<N;++i) {M[i]=new int[N]; for(int j=0;j<N;++j) M[i][j]=0;}
//i-ый отрезок вложен в j-ый for(int i=0;i<N;++i) for(int j=0;j<N;++j) if(Left[j]<Left[i] && Right[i]<Right[j]) {M[i][j]=1; M[j][i]=-1;} delete[] Left;delete[] Right; return 0; } int doing(int &N,int **(&M),int *(&Last),int &posBiggestWeight,int &BiggestWeight){ Last=new int[N]; int *Weight=new int[N]; for(int i=0;i<N;++i) {Last[i]=-1; Weight[i]=0;}
//Поиск отрезков, которые ни во что не вложены int *Roots=new int[N],iCountRoots=0; for(int i=0;i<N;++i){ bool isNotRoot=true; for(int j=0;j<N && isNotRoot;++j) if(M[i][j]==1) isNotRoot=false; if(!isNotRoot){ Roots[iCountRoots++]=i; } } //Перебор всех вложеных for(int k=0;k<iCountRoots;++k){ int NeedVisit[1000000],cntNVisit=0; NeedVisit[cntNVisit++]=Roots[k]; Weight[Roots[k]]=0; while(cntNVisit>0){ int tekVertex=NeedVisit[--cntNVisit],tekWeight=Weight[tekVertex],newWeight=tekWeight+1; for(int j=0;j<N;++j) if(M[tekVertex][j]==1 && newWeight>=Weight[j]){ NeedVisit[cntNVisit++]=j; Weight[j]=newWeight; Last[j]=tekVertex; } } } //поиск максимального веса BiggestWeight=-2; posBiggestWeight=-1; for(int i=0;i<N;++i) if(Weight[i]>BiggestWeight){ posBiggestWeight=i; BiggestWeight=Weight[i]; } delete[] Weight; return 0; } int saveing(int &N,int* (&Last),int &posBiggestWeight,int &BiggestWeight){ int *Answer=new int[BiggestWeight+1],pos=posBiggestWeight; int indAnswer=BiggestWeight; while(pos!=-1){ Answer[indAnswer--]=pos+1; pos=Last[pos]; } printf("%d\n",BiggestWeight+1); for(int i=0;i<BiggestWeight;++i) printf("%d ",Answer[i]); printf("%d\n",Answer[BiggestWeight]); delete[] Answer; return 0; } int main(){ int N,**M,*Last,posBiggestWeight=0,BiggestWeight=0; int res=loading(N,M); if(res==-1) return 0; doing(N,M,Last,posBiggestWeight,BiggestWeight); saveing(N,Last,posBiggestWeight,BiggestWeight); delete[] Last; for(int i=0;i<N;++i) delete[] M[i]; delete[] M; return 0; } 1) Don't forget, that pupils sit in a circle! 2) You have to count how many pupils you can satisfact with choice 'i' boy at first (even he doesn't to be so :-) ). There are algo claimed O(n) 3) If you have such info, it's so easy to calculate the answer ;-) I can send the solution to your mail. This algo gets TL too... plz send me code to rockprogressive.s[at]gmail.com Hi, Yes the problem can be solved by thinking about it as a voting problem. Consider the following input: 5 3 3 1 5 5 1st student wants 4th student to go first. 2nd student wants 5th student to go first. 3rd student wants 3rd student to go first. 4th student wants 5th student to go first. 5th student wants 1st student to go first. 5th student receives the maximum votes so answer is 5. Consider another example from the problem test case. 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. Another example from a test case taken from elsewhere in the forum: 8 1 2 3 5 5 6 7 8 1st student wants 1st student to go first. 2nd student wants 1st student to go first. 3rd student wants 1st student to go first. 4th student wants 8th student to go first. 5th student wants 1st student to go first. 6th student wants 1st student to go first. 7th student wants 1st student to go first. 8th student wants 1st student to go first. So the answer is 1. Edited by author 10.01.2011 04:57 My solution: Calc b[i] - count of numbers such (n+A[i]-i)%n == i Then find max_idx - index of maximum element in array b answer is (n - max_idx) % n + 1 did you get AC? I don't think to satisfy most students is right. for example(the one you mentioned): 5 3 3 1 5 5 your answer is 5,so the sequence is 2 3 4 5 1. we can calculate the difference: |3-2|+|3-3|+|1-4|+|5-5|+|5-1|=8 but for another sequence:1 2 3 4 5,the difference is: |3-1|+|3-2|+|1-3|+|5-4|+|5-5|=6, is smaller than 8. so as my conclusion, we should make the "displeasure" minimal. if using your method, maybe a lot of students is "satisfied(the difference of him is 0)", but others maybe larger. sorry for my bad English. did you get AC? I don't think to satisfy most students is right. for example(the one you mentioned): 5 3 3 1 5 5 your answer is 5,so the sequence is 2 3 4 5 1. we can calculate the difference: |3-2|+|3-3|+|1-4|+|5-5|+|5-1|=8 but for another sequence:1 2 3 4 5,the difference is: |3-1|+|3-2|+|1-3|+|5-4|+|5-5|=6, is smaller than 8. so as my conclusion, we should make the "displeasure" minimal. if using your method, maybe a lot of students is "satisfied(the difference of him is 0)", but others maybe larger. sorry for my bad English. Hi, Yes the problem can be solved by thinking about it as a voting problem. Consider the following input: 5 3 3 1 5 5 1st student wants 4th student to go first. 2nd student wants 5th student to go first. 3rd student wants 3rd student to go first. 4th student wants 5th student to go first. 5th student wants 1st student to go first. 5th student receives the maximum votes so answer is 5. Consider another example from the problem test case. 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. Another example from a test case taken from elsewhere in the forum: 8 1 2 3 5 5 6 7 8 1st student wants 1st student to go first. 2nd student wants 1st student to go first. 3rd student wants 1st student to go first. 4th student wants 8th student to go first. 5th student wants 1st student to go first. 6th student wants 1st student to go first. 7th student wants 1st student to go first. 8th student wants 1st student to go first. So the answer is 1. Edited by author 10.01.2011 04:57 I got AC for voting solution... 4 4 1 2 3 1st student wants 2nd student to go first. 2nd student wants 2nd student to go first. 3rd student wants 2nd student to go first. 4th student wants 2nd student to go first. So, the answer is 4. typo i'd rather like this. cuz it's clear :) You should just pay attention to the sentence: "The last tram leaves from the Shau Kei Wan station BEFORE the first tram finishes its first cycle". Therefore the solution you found may not be correct. Good Luck! What is test case 13? Getting a wrong answer on that case. I had WA13 on FreePascal with TStringList.IndexOf() method. Try write IndexOf (or what you use) "manually". Perhaps this is due to hidden features of string conversion/comparison. My code: What's wrong??? #include <algorithm> #include <vector> #include <utility> #include <stdio.h> #define ARRAY_SIZEOF(a) (sizeof(a) / sizeof(a[0])) #define INF 0x7fffffff using namespace std; typedef long long int lli; int M, N; int C[100][500]; int T[101][500]; int m1[500]; int m2[500]; int path[500*500]; int main() { #ifndef ONLINE_JUDGE freopen("in", "r", stdin); #endif int i, j, k; scanf("%d%d", &M, &N); for (i = 0; i < M; i++) { for (j = 0; j < N; j++) { scanf("%d", &C[i][j]); C[i][j]++; T[i+1][j] = INF; } } for (i = 1; i <= M; i++) { m1[0] = T[i-1][0] + C[i-1][0]; for (j = 1; j < N; j++) { m1[j] = min(m1[j-1], T[i-1][j]) + C[i-1][j]; } m2[N-1] = T[i-1][N-1] + C[i-1][N-1]; for (j = N-1; j-- > 0; ) { m2[j] = min(m2[j+1], T[i-1][j]) + C[i-1][j]; } for (j = 0; j < N; j++) { T[i][j] = min(m1[j], m2[j]); } } int jmin = 0; for (j = 1; j < N; j++) { if (T[M][j] < T[M][jmin]) { jmin = j; } } i = M; j = jmin; k = 0; do { path[k++] = j + 1; int m = T[i-1][j]; jmin = j; if (j-1 >= 0 && T[i][j-1] < m) { jmin = j-1; m = T[i][jmin]; } if (j+1 < N && T[i][j+1] < m) { jmin = j+1; m = T[i][jmin]; } if (m == T[i-1][j]) i--; else j = jmin; } while (i); for (i = 0; i < k; i++) { printf("%d ", path[k-1-i]); } printf("\n"); return 0; } I sort the the 2^k states by the bits it contains, then check the states in order, and always TLE #22 Then, I choose a state randomly in the 2^k states and check if it's legal, and get accepted…… part of my code: 63 int ans = (1 << k) - 1; 64 int tot = 1 << k; 65 int times = 0; 66 while (tot > 0 && (times * realm < (500000000))) { 67 int now = rand() % tot; 68 if (countBit(arr[now]) < countBit(ans)){ 69 memset(visit,0,sizeof(visit)); 70 times++; 71 if (dfs(0,arr[now])) { 72 ans = arr[now]; 73 } 74 } 75 arr[now] = arr[--tot]; 76 } If you use G++, it's better to use standart function (__builtin_popcount(n)) instead of countBit(n) try this test: 11 + 11 ##### 22 |
|