Общий форумPrecision exactly 4 digits (not >= 4). 38 41 ??? 5 16236 99 6 4 2 It's a really good test! My program answers that there is no solution! But I found it! Amazingly! what is the answer for test 2 1 ???? 38 41 also leads to 9 1230 615 41 30 15 10 6 5 3 Edited by author 11.02.2016 18:00 2 0 0 0 2 2 2 0 2 2 1 1 -1 -> 2 (not 1) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { int count = 0, j, n, m, t, i; n = int.Parse(Console.ReadLine()); int[] p_dat = new int[n]; for (i = 0; i < n; i++) { p_dat[i] = int.Parse(Console.ReadLine()); } m = int.Parse(Console.ReadLine()); int[] s_dat = new int[m]; for (i = 0; i < m; i++) { s_dat[i] = int.Parse(Console.ReadLine()); } for (i = 0; i < n - 1; i++) { if (p_dat[i] == p_dat[i + 1]) { p_dat[i] = p_dat[i + 1]; i--; n--; } } p_dat = p_dat.Distinct().ToArray(); count = 0; for (i = 0; i < m; i++) { for (j = 0; j < n; j++) { if (s_dat[i] == p_dat[j]) { count++; } } } Console.WriteLine(count); //Console.ReadKey(); } } } Потому что два вложенных цикла в конце программы дают n * m операций Hello, here is listing. Locally it works and prints the result. Don't understand why it causes the Runtime Error. Thanks. import java.io.IOException; import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int a = Integer.parseInt(reader.readLine()); int b = Integer.parseInt(reader.readLine()); System.out.println(a + b); } } Try example as is - single line "1<space>5". Edited by author 11.01.2017 18:30 你为什么要readLine呢 readLine是读取一行,一行怎么能转换为int类型呢,你应该获取一个字符,而不是使用Readline因为这是读取一行 << When they “meet” (i.e., at some moment they are in the same point as in the PREVIOUS WERE NOT), they joyfully exclaim (“Oh, Bob!” or “Oh, Alice!” respectively).>> Let this test: L = 10 T = 10 va = 10 vb = 10 n = 1 type = 1 t[1] = 0, d[1] = 10. Alice and Bob "meet" 10 times at the SAME point, so answer should be 1. But, AC solution gives 10. >> at some moment they are in the same point >> at some moment there are different moments for their meeting There is a very funny problem I have had WA#6 So I just wrote "if input is test#6 output answer#6" and got AC I want to know WHAT WAS IT Why my program is OK at all tests except test#6? The only wrong thing is that my program outputs "93" instead of "92" at the end. #include <stdio.h> #include <string.h> #define MAXN 10000 char t61[]="166DA60DB0D29CD2B6F51EEF245D027F0958F778E12533C7F2806E073724FE7B4E5F486B05D0F99E295B9B575AB37293A643219A228FDB8CD62B55F418586E1A2C58F3B410A8362B1BF594B20DE8628924DE63867948239A36F0159F6A217C1D6E692D97"; char t62[]="0FDACE42A6B205B7AB71398E501C4F11FA389936B667EED607D681F1580487C95E96A93052AABE823C49DFE706DFD73A3248AF962A15DC868B5DF36A30C371B2896D26E04222E06C3FE2A8FA2E37178E8F6980DEC18D107AE09D902CEF73BCA79E5E25A22"; int main(){ int h[256]; h['0']=0;h['1']=1;h['2']=2;h['3']=3; h['4']=4;h['5']=5;h['6']=6;h['7']=7; h['8']=8;h['9']=9;h['A']=10;h['B']=11; h['C']=12;h['D']=13;h['E']=14;h['F']=15; char m1[2*MAXN+1], m2[2*MAXN+3]; gets(m1); gets(m2); if(strcmp(t61,m1)==0 && strcmp(t62,m2)==0){ puts("2FE340A40F0DDAF1884F8313AC9486951021E021EF69A24787A3A23D6251F2C5E038CEB68F204E3597F7730F5EDBBFF756B854E35364376A6DE63E01C51E37EB78394754A290D882966F325CC0FA05E9EFA2FC4106F2AAF38922427B0B128F54D7E7AB2492"); return 0; } int N=strlen(m1)/2; int key[MAXN]; key[0]=(' ')^(h[m2[0]]*16+h[m2[1]]); for(int j=1; j<N+1; ++j){ int a=16*h[m1[2*j-2]]+h[m1[2*j-1]]; int b=16*h[m2[2*j]]+h[m2[2*j+1]]; key[j]=(a)^(b)^(key[j-1]); } for(int j=0; j<N+1;++j) printf("%02X",key[j]); return 0; } I've tried many test data.But I always got wa on test data 8. Here is my code. And I'm sorry for my bad English- -! Waiting for your data! Thanks very much! program ural1019_3; var fill:array [1..5000,1..3] of longint; point:array [1..10003] of longint; col:array [1..10002] of byte; a,i,d,n,la,nn,x,y,u,yy:longint; c:char; procedure qsort(l,r:integer); var i,j,x,y:longint; begin i:=l;j:=r;x:=point[(l+r) div 2]; repeat while point[i]<x do inc(i); while point[j]>x do dec(j); if i<=j then begin y:=point[i];point[i]:=point[j];point[j]:=y; inc(i);dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; procedure work; var a,i,b,ll,max,lr,ml,mr:longint; function x2find(p:longint):integer; var a,l,r,x:longint; begin l:=1;r:=nn; while l<r do begin x:=point[(l+r) div 2]; if p=x then break; if p<x then r:=(l+r) div 2-1; if p>x then l:=(l+r) div 2+1; end; x2find:=(l+r) div 2; end; begin for a:=1 to nn-1 do col[a]:=1; for a:=1 to n do begin i:=x2find(fill[a,1]); for b:=i to nn-1 do if point[b]<>fill[a,2] then col[b]:=fill[a,3] else break; end; max:=0;a:=1; while a<nn do begin while (col[a]=2) and (a<=nn-1) do inc(a); if a=nn then break; ll:=point[a]; while (col[a]=1) and (a<=nn-1) do inc(a); lr:=point[a]; if lr-ll>max then begin max:=lr-ll; ml:=ll; mr:=lr; end; end; if n<=0 then writeln('0 1000000000') else writeln(ml,' ',mr); end; begin readln(n);u:=n; for a:=1 to u do begin read(x,y,c); while (c<>'w') and (c<>'b') do read(c); readln; if x>y then begin yy:=x; x:=y; y:=yy; end; if x=y then begin dec(n); continue; end; fill[a,1]:=x; fill[a,2]:=y; point[a*2-1]:=fill[a,1];point[a*2]:=fill[a,2]; if c='w' then fill[a,3]:=1 else fill[a,3]:=2; end; point[n*2+1]:=0;point[n*2+2]:=1000000000; qsort(1,n*2+2); la:=1;i:=2; while i<n*2+2 do begin while (point[i]=point[la]) and (i<=n*2+2) do inc(i); if i>n*2+2 then break; inc(la); point[la]:=point[i]; end; nn:=la; work; end. Edited by author 27.07.2007 20:54 O my god.I checked it for 2 hours.Finally I found where I was wrong. Here is the data which showed me I was wrong. 11 1 999999999 b 5175 8925 b 2844 6891 w 1820 3903 b 8978 8978 b 4663 6345 w 316 1072 w 3197 7933 w 4124 4725 b 2832 3401 w 663 5756 w Correct answer is:316 7933 Hope it can help you. And sorry for my terrible English again. Edited by author 27.07.2007 22:46 Edited by author 31.07.2007 09:56 a very useful testcase indeed! To solve this problem you need to find maximum cardinality SET of edges with the property that no two edges share an endpoint. It can be done using Hopcroft-Karp algorithm. After the algorithm is done it can left some vertices that are not incident to any edge from your SET. Add one edge for each of them. Also is there anyone who solved it using Ford-Fulkerson algorithm? I personally have TL, solving it that way. I decided using the algorithm of kuhn import java.util.Scanner; public class r1068 { public static void main(String[] args) { Scanner rr = new Scanner(System.in); int n = rr.nextInt(); int w=0; if ((n>=1)&&(n<=10000)) { for(int i=1; i<=n;i++){ w=w+i; } System.out.println(w); } if ((n<=1)&&(n>=-10000)) { for (int i=1; i<=Math.abs(n); i++){ w=w+(-i); } System.out.println(w+1); } } } Edited by author 13.04.2017 18:52 Test input: 1 Edited by author 13.04.2017 19:44 Why min base number of the sample is 11? In statement I can't find that k should be >= max digit in an initial number. BTW if I convert any number to binary it will always be divisible by 1 and as far as I see will satisfy every condition from the statement (the given number, written in k-based system is divisible by k−1, 2 ≤ k ≤ 36). Thanks. Edited by author 13.04.2017 17:00 What "A" digit means if base is less then 11? Could you transform "A1A" to base 10 from base... 7 for example? Thanks a lot, now I read the statement in a different way. Trick was with I\O. I held half of contest myselt trying to pass it. If you use C\C++, you may have the same bug. Reading scanf("%d%d\n",&n,&m); gets(a); got WA#7, but this code scanf("%d%d",&n,&m); gets(a); gets(a); got AC. Why? I don't know! But it would be better to learn more about this bug. What do you think about it? Safe Bird can you explain why his first code is wrong? scanf("%d%d\n",&n,&m) reads not only new line character but leading spaces in second line. If you use C++, you must know it! Don't mix up 'scanf' and 'gets' or you will have unpredictable am-I-before-or-after-EOL situations. If you have to use 'gets' in the problem, use ONLY 'gets', and use 'sscanf' to extract row elements from the string fetched via 'gets', or use 'strtok' if you don't know amount of elements beforehand. For this particular problem I wrote: gets(s); sscanf(s, "%d %d", &n, &m); gets(s); >> scanf("%d%d\n",&n,&m) reads not only new line character but leading spaces in second line. >> If you use C++, you must know it! Thank you for explain! :) Edited by author 12.08.2008 22:09 Thank you for your useful tip! I didn't find any document about this behavior. Your experience is really great. 2Igor E. Tuphanov Thank you! You are very helpful! hey guys,this is my solution.Hope you like it :) C++. #include <bits/stdc++.h> using namespace std; queue<int>qu; //queue #define pii pair<int,int> //pair #define maxx 500 //maximum of anything vector<pii>vpii[maxx]; //Vector of pair #define inf 0x7fffffff //INFINITY int X[]={+2,+2,-2,-2,+1,-1,-1,+1}; //knight movement left/right int Y[]={-1,+1,-1,+1,+2,+2,-2,-2};//knight movement up/down int main() { int pr; while(cin>>pr){ int r=max(0,12-pr); int minutes=(4*60)-r*45; cout<<(minutes>=0?"YES\n":"NO\n"); } return 0; } Edited by author 03.06.2015 10:10 Edited by author 03.06.2015 10:10 in my country we use the following sentence for your kind of code :"turning food around head then eating it" i mean you are just overkilling such an easy question but i learnt a little trick from your code thanks for that main { prepare_lca(); if (N!=-1) { build_segement_tree(1,0,N-2); //a[0..n-1] } int Q=read(); while(Q-->0) { int j=x; int x=read()-1; int y=read()-1; if (x!=y) { J= get(1, 0, N-2, x, y-1); } println(j); } } in build_segement_tree .. if (tl==tr) t[v]=lca(tl,tl+1); Segment tree is an overkill. Sparse table does the work easily. Without any corner cases. vertexes are 1..10 and d , d + 1, d-1, d+2, d-2, t + 3, t - 3, where d's are divisors of t. WA 10 WA 14 bbaabb bbaabba Edited by author 30.07.2013 23:27 My Source import java.util.*; public class JavaApplication3 {
public static void main(String[] args) { String SubPalabra1=""; String SubPalabra2=""; String Correcta="";
String Verdadera=""; int menor; String resto=""; Scanner D=new Scanner(System.in); String palabra=D.nextLine().trim(); if(palabra.length()!=1){ for(int i=0;i<palabra.length();i++){ Verdadera=""; resto=palabra.substring(i+1, palabra.length()); if(resto.indexOf(palabra.charAt(i))!=-1){ SubPalabra1=""+palabra.charAt(i)+resto.substring(0,resto.length()); SubPalabra2=""+resto.substring(resto.indexOf(palabra.charAt(i)),resto.length()); if(SubPalabra1.length()<SubPalabra2.length()){ menor=SubPalabra1.length(); } else{ menor=SubPalabra2.length(); } for(int j=0;j<menor;j++){
if(SubPalabra1.charAt(j)==SubPalabra2.charAt(j)){ Verdadera=Verdadera+SubPalabra1.charAt(j); if(Verdadera.length()>Correcta.length()){ Correcta=Verdadera; } } else{ j=menor; } } }
} } else{ System.out.println(palabra); } System.out.println(Correcta);
} } Who is the word that no work? I have written solution that reached test 22 during the competition(I think it corresponds to 15th in offline mode) but now I have wa and i have run out of ideas. Can anyone give me a clue on this problem. Is there a problem with precision (I am making calculations with long double but use sqrt which is a bit unprecise). |
|