Общий форумvery usual segment tree, that helps to fill dynamic vars. I wonder if anyone have been had the same problem... help! found it; I wasn't careful about the length of the array. Edited by author 16.07.2013 08:53 Edited by author 16.07.2013 08:53 I didn't get accepted until I switched printf() with cout. I used %lld for the format of printf and still it got WA. Same formula, same code, just that i used cout/cin and I got AC. I used printf with "%llu" and got AC the first attempt. u - unsigned d - digit (signed) cin>>n>>m not while(cin>>n>>m) why?? #include<cstdio> #include<algorithm> #include<iostream> #include<cmath> #include<climits> #include<string> #include<string.h> #include<vector> #define sf scanf #define pf printf #define cls(a) memset(a,0,sizeof(a)) #define _cls(a) memset(a,-1,sizeof(a)) using namespace std; struct Edge_t{ int to,next; }edge[400000]; int hed[200000]; int et; struct tree{ tree *br[26]; vector<int>vec; tree(){ for(int i=0;i<26;++i) br[i]=NULL; vec.clear(); } }; struct Input{ char str[18]; int val; }inp[100010]; tree *head; inline void adde(int u,int v){ edge[et].to=v,edge[et].next=hed[u],hed[u]=et++; } inline void addtree(char *st,int index){ int id,i; tree *s=head; for(i=0;st[i];++i){ id=st[i]-'a'; if(!s->br[id]) s->br[id]=new tree; s=s->br[id]; } s->vec.push_back(index); } inline bool cmp(int a,int b){ if(inp[a].val==inp[b].val) return strcmp(inp[a].str,inp[b].str)<0; return inp[a].val>inp[b].val; } void DEL(tree *s){ int i; for(i=0;i<26;++i) if(s->br[i]) DEL(s->br[i]); s->vec.clear(); delete(s); } int res[1000010]; void deal(char *st,int index){ int i,id,j; tree *s=head; for(i=0;st[i];++i){ id=st[i]-'a'; if(!s->br[id]) return; s=s->br[id]; for(j=0;j<s->vec.size();++j) adde(s->vec[j],index); } } int main(){ int i,j; int n,m,sk; char str[18]; while(scanf("%d",&n)!=EOF){ head=new tree; _cls(hed); for(i=et=0;i<n;++i) sf("%s%d",inp[i].str,&inp[i].val); sf("%d",&m); for(j=0;j<m;++j){ sf("%s",str); addtree(str,j); } for(i=0;i<n;++i) deal(inp[i].str,i); int e; for(i=0;i<m;++i){ if(i) puts(""); for(sk=0,e=hed[i];e!=-1;e=edge[e].next) res[sk++]=edge[e].to; if(!sk) continue; sort(res,res+sk,cmp); //if(sk>0) for(j=0;j<sk && j<10;++j) pf("%s\n",inp[res[j]].str); } DEL(head); } return 0; } /* 2 ab 10 ac 20 1 f */ after an hour of realizing how to receive the inputs, here I am failing at test 9. the code looks right to me any ideas? import java.util.*; import java.io.*; public class lucky {
public static void main(String[] args) throws IOException{
BufferedReader cin = new BufferedReader(new InputStreamReader(System.in));
double[] ans=new double[64000];
int n=0; StringTokenizer st; while (true) try{
st=new StringTokenizer(cin.readLine()); while (st.hasMoreTokens()){ ans[n]=java.lang.Math.sqrt(Double.parseDouble(st.nextToken()));
n++; } //System.out.println("log");
if (!cin.ready()) throw new Exception();
} catch (Exception ex) {break;}
n--; for(; n>=0; n--) System.out.printf("%.5f\n", ans[n]); }
} The input stream is said to be 256KB at maximum, which means it can have 131072 numbers at maximum, if a KB is meant to be 1024 bytes. But you output no more than 64000 numbers. So I assume your program fails on inputs with many numbers. #include <iostream> #include <cstdio> using namespace std; int main() { double *n = new double[1000]; double *m = new double[1000]; int l=0; int r=0; while(getchar() != EOF) { scanf("%lf",&n[l]); l++; } for(r=l; r>0; r--) { m[r]=sqrt(n[r]); cout << m[r]; } } Вот на основе твоего кода. массив m мне кажется лишний здесь. getchar "съедал" символ. cout выводит без заданной точности. #include <iostream> #include <math.h> using namespace std; int main() { double *n = new double[10000000]; double buf; int l=0; while(scanf("%lf",&buf) != EOF) n[l++]= sqrt(buf); l-=1; while (l>=0) printf("%.4f\n",n[l--]); } it's not standard problem input: 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. |
|