Common Boardimport java.io.*; import java.util.*; public class JavaApplication10 { public static void main(String[] args) throws FileNotFoundException { Scanner s=new Scanner(System.in); int N=s.nextInt(); int R=s.nextInt(); ArrayList<Double> gvozdi_x= new ArrayList<>(); ArrayList<Double> gvozdi_y= new ArrayList<>(); for(int i=0;i<N;i++) { double x; x = s.nextDouble(); gvozdi_x.add(x); double y; y = s.nextDouble(); gvozdi_y.add(y); } double d; double k=0; for(int i=0;i<N;i++) { if((i+1)==N){ d=Math.sqrt(Math.pow(gvozdi_x.get(0)-gvozdi_x.get(i),2.0)+(Math.pow(gvozdi_y.get(0)-gvozdi_y.get(i),2.0))); } else{ d=Math.sqrt(Math.pow(gvozdi_x.get(i+1)-gvozdi_x.get(i),2.0)+(Math.pow(gvozdi_y.get(i+1)-gvozdi_y.get(i),2.0))); } k=k+d; } double P=2*3.14*R; k=k+P; String l; l=String.format("%.2f",k); System.out.println(l); } } Edited by author 21.07.2013 14:49 4 3 1 2 2 1 3 2 1 3 Nope, And I quote "There is at most one road between any two cities". using System; namespace ConsoleApplication5 { class Program { static void Main(string[] args) { string[] A = Console.ReadLine().Split(' '); float a = int.Parse(A[0]); float b = int.Parse(A[1]); if (a <= b) Console.WriteLine(2); else Console.WriteLine("{0:#}",a/b*2); } } }
your formula is not correct, think of more cases Any hints? thanks... my approach is to use bfs Edited by author 14.01.2013 05:59 I’m using dijkstra algorithm. I have WA 11 too. I see you managed to pass this test. Could you tell me please, what is the test 11? I don’t think this problem can be solved by BFS, is it? Thanks, Thank you very much, I'll learn and implement those hints as soon as I finish Facebook Hacker Cup 2013 problems, Hopefully I can get AC. good luck for it... apparently it is now too late for me to join.. Thanks, Yes, it is late now, but next year if you register once, you can participate every year. And in April there will be Google Code Jam 2013, you can participate in that contest. I don’t think this problem can be solved by BFS, is it? I solved this by using BFS. But everytime I adds into queue all not used vertices, reachable from the current vertex along ribs of one and the same direction. I don’t think this problem can be solved by BFS, is it? You are wrong, I wrote simple bfs and its got ac with the second attempt:) Could you give any hint to bfs? Делал на питоне: import math def solve(): n = input() s = '' for i in xrange(n): k = input() d = math.sqrt((k << 3) - 7) result = int(d) if result == d and result & 1: s += '1 ' else: s += '0 ' print s solve() Выдает TL, как ускорить? Пробовал сразу ответ выводить - на моих тестах это дольше по времени. k << 3 заменял на k * 8, result & 1 менял на result % 2 - все равно TL. Python 2.7 Для себя понял, что самое времязатратное - ввод/вывод. Поэтому AC получил так: import math import sys stringArray = sys.stdin.read().split() i = 0 s = '' for string in stringArray: if i == 0: i += 1 continue k = int(string) d = math.sqrt((k << 3) - 7) result = int(d) if result == d and result & 1: s += '1 ' else: s += '0 ' print s Но все равно интересует - есть ли способ ускорить первое решение? For not to use long arithmetic, notice that if you get a value < −2·10^9 or > 2·10^9 by calculating fib[i] in the the range [min(i, j, n); max(i, j, n)] then you can assign fib[i] = -2*10^9-1 or 2*10^9+1 respectively. var f,i:longint; k:1..20; n:1..10; s:string; begin readln(n); read(s); f:=1; k:=length(s); for i:=0 to (n div k)-1 do begin f:=f*(n-i*k); end; writeln(f); end. Nargiza sizning xatoyingiz sonni va faktarialni ajratib olishda, va bundan tashqari hisoblash tsiklida n dan 1 ga tomon qadam k shaklida oling ya'ni.....qanday hisoblash tsiklida n dan 1 ga tomon qadam k shaklida olinishi kerak sizda menimcha kiritish jarayonida raqam(n) va undov(!) orasida probel(_) qo'ymasdan yozganda xato ishlashi mumkin. shunda undovlarni ham raqam sifatida o'qib s ni uzunligi 0 ga teng bo'lib qoladi. shuning uchun n/l(n bo'lingan s ning uzunligi) n/0 bo'lib qolyapti shunda sizga Crash (integer division by zero) ashibka beryapti #include <iostream> using namespace std; int main() { int n,t,s; cin>>n; char k[20]; gets(k); s=n; t=n%(strlen(k)-1); if(t!=0) while(n>t) { n=n-(strlen(k)-1); s*=n; } else while(n>(strlen(k)-1)) { n=n-(strlen(k)-1); s*=n; } cout<<s<<endl;
return 0; } По моему эта задача не имеет ничего общего со спортивным програмированием I'm pass test only after add ignoring for empty input lines. why empty lines present in tests? There is no empty lines in tests. But the input is finished by EOLN, as usual on Timus Online Judge. Edited by author 17.07.2013 18:22 May be this tests will help to some others. When my prog passed all of them , I'v get AC. 12 putone inputon outputoutputinputon inputone putin outputin puton inonputin oneputonininputoutoutput oneininputwooutoutput outpu utput Answers: NO YES YES YES NO YES YES NO YES NO NO NO "putin" is the best test. =) And you forgot to tell about copyrights of this test =)))) It is possible to read data without MLE (Thanks to Fyodor Menshikov) and TLE (Thanks to Alex Tolstov ). And make very-very-simple DFA by reading from end to the begining of data string. If you will read "As is" you will have some problems with creating DFA :) My AC program using this "back reading" in Java works 0.625 s And use 10 390 КБ Good luck! Edited by author 29.07.2009 19:37 Hello, how does your programm do back reading? Can you post that part of your program? Hello, how does your programm do back reading? Can you post that part of your program? Just one char array of 10^7 of chars with "reused" for reading lines of char. Use BufferedReader to read bytes from input. Not Scanner. Edited by author 19.07.2012 03:10Thanks, man. You helped me to fix some problems in my state/event table :) People, be afraid of mistyping! Give me sixth test, please!!! i also have WA on 6 test, please, give me some tests. 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? |
|