Общий форум5 1 2 3 4 5 1 3 1 3 4 5 4 5 4 5 I think the correct answer of this sample is "Let's search for another office.", but my program outputs "Ask Shiftman for help." I just couldn't squeeze my bipartite matching through the TL... Anyway, a nice test against extra greediness: 3 40 50 60 30 70 20 40 50 50 Perfect! 3 1 2 Please tell me the reason or give me the t4,thank you! This is my program: #include <cstdio> #include <iostream> #include <cstring> using namespace std; int n,result=0,xia=0,rxia; int line[110][2],era[110][2],fera[110][2]; void init() { int i,j; scanf("%d",&n); for(i=1;i<=n;i++) { scanf("%d %d",&line[i][0],&line[i][1]); if(line[i][0]>line[i][1]) swap(line[i][0],line[i][1]); } for(i=1;i<n;i++) for(j=i+1;j<=n;j++) { if(line[j][0]<line[i][0]) { swap(line[i][0],line[j][0]); swap(line[i][1],line[j][1]); } if(line[j][0]==line[i][0]) if(line[j][1]<line[i][1]) { swap(line[i][0],line[j][0]); swap(line[i][1],line[j][1]); } } } void jilu(int i) { xia++; era[xia][0]=line[i][0]; era[xia][1]=line[i][1]; } void copyera() { int i; for(i=1;i<=xia;i++) { fera[i][0]=era[i][0]; fera[i][1]=era[i][1]; } } void solve() { int i,x,temp=1,now; for(x=1;x<=n;x++) { xia=0; temp=1; memset(era,0,sizeof(era)); xia++; era[xia][0]=line[x][0]; era[xia][1]=line[x][1]; now=line[x][1]; for(i=x+1;i<=n;i++) if(line[i][0]>=now) { temp++; now=line[i][1]; jilu(i); } if(temp>result) { result=temp; copyera(); rxia=xia; } } printf("%d\n",result); for(i=1;i<=rxia;i++) printf("%d %d\n",fera[i][0],fera[i][1]); } int main() { init(); solve(); return(0); } Thank you very much!!! Maybe you forget sort first just like me. var a: array[1..1000, 1..10001] of integer; c, d, e: integer; label 1; begin randomize; d := 1; Readln(c); for e := 1 to c do read(a[e, 10001]) {a[e,1002]:=random(c-1)+1}; for e := 1 to c do a[e, 1] := e; 1: inc(d); //for e:= 1 to c do write (a[e,1001],' '); for e := 1 to c do a[a[e, 10001], d] := a[e, d - 1]; for e := 1 to c do if a[e, d] <> a[e, 1] then goto 1; writeln(d - 1); end. when i was writing my first solution i used ceil and log functions for calculating how many computers get copies with available cables (without using the same number of cables as one copy before)... so i calculated "int init = (int)ceil(log((double)k) / log(2.0));" and used that in my program but i got WA#6... then i wrote my own function that does exactly the same: int getPow(int x) { int c = 0; int n = 1; while(n < x){ c++; n *= 2; } return c; } and then i got AC... can someone explain in what case the ceil and log functions would give wrong results. THANK YOU I also didn't got that, but this is fact: I changed my ceils and logs to self-written function and got AC. It is still challenge for me to explain, why I've do the same.... Maybe the problem is due to the compiler... Same here....and I compared my log2(x)) to (int)(log((double)x) / log(2.0)) for all x from 1 to 0x7FFFFFFF on my system and they're all identical. You needn't use function log() or something else,You can use a const array like (2,4,8,16,32,64,128,256,512,1024....). PLOBLEM 1: I have seen the topic "c WA why?",and I have a problem:Why the for cycle's range should be 1 to 2*n but not 1 to n?Help me,I don't know. PLOBLEM 2: my program: #include<stdio.h> #include<string.h> #include<stdlib.h> int n,max=0,count[3],a; char s[30],ans,max1; int main() { freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); scanf("%d",&n); count[1]=0;count[2]=0;count[3]=0; for(int i=1;i<=2*n;i++) { scanf("%s",s); if(s[0]=='E') { count[1]++; if(count[1]>max) {max=count[1];max1='E';} } else if(s[0]=='L') { count[2]++; if(count[2]>max) {max=count[2];max1='L';} } else if(s[0]=='M') { count[3]++; if(count[3]>max) {max=count[3];max1='M';} } } if(max1=='E') printf("Emperor Penguin"); else if(max1=='L') printf("Little Penguin"); else if(max1=='M') printf("Macaroni Penguin"); return 0; } It can be right in my conputer(printf"Macaroni Penguin"),but it's WRONG#1 in the test. And if I change for cycle's range into 1 to n,it's WRONG,and printf"Emperor Penguin" I don't know. SO,please help me,thank you! now,this problem can pass #6 point,but W7 #include<stdio.h> #include<string.h> #include<stdlib.h> int n,max=0,count[3],a; char s[30],ans,max1,e=0,l=0,m=0; int main() { scanf("%d\n",&n); count[1]=1;count[2]=1;count[3]=1; for(int i=1;i<=2*n;i++) { scanf("%s",s); if(s[0]=='E') e++; else if(s[0]=='L') l++; else if(s[0]=='M') m++; } if(e>l&&e>m) printf("Emperor Penguin"); if(l>e&&l>m) printf("Little Penguin"); if(m>e&&m>l) printf("Macaroni Penguin");
//system("pause"); return 0; } Edited by author 24.02.2013 07:27 Edited by author 24.02.2013 07:42 main() { int n,i; long a[1001],maxsum=0,nsum,nmaxsum,sum=0; scanf ("%d",&n); for (i=0; i<n; i++) { scanf ("%ld",&a[i]); if (i>=2) { if (a[i-2]==a[i-1] && a[i-1]==a[i]) { sum=a[i-2]+a[i-1]+a[i]; nsum=i; }
if (sum>=maxsum) { maxsum=sum; nmaxsum=nsum; } }
} printf ("%ld %d",maxsum, nmaxsum);
} //SESC USU SUDO RM -RF var a,b,c,d,i:integer; begin read(a,b); d:=0; for i:=1 to b do begin read(c); if d<0 then d:=0; d:=d-(a-c); end; if d > 0 then writeln (d) else writeln ('0'); end. Edited by author 01.12.2012 17:40 Sudo -rm -rf Rulez By Me! decomposed into prime factors, and then submit to the canonical form then you will get AC!!! It is a good idea! I used the same method! import java.util.Scanner; public class Computers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int a = 0; int com = in.nextInt(); int mod = in.nextInt();
if (mod == 1 && com == 1 ){ System.out.println(mod); return; }
for(int x = 1;x < com;){ if (x == 1){ x++; a++; } if (x - mod == 0 && com - x > mod){ x+=mod; a++; }else if (x - mod == 0 && com - x < mod){ x+= com - x; a++; } if (x < mod && com - x > mod){ x+=x; a++; }else if (x < mod && com - x < mod){ x+= com - x; a++; } if (x > mod && com - x > mod){ x+=mod; a++; }else if (x > mod && com - x < mod){ x+= com - x; a++; }
} System.out.println(a); } } No, I don't, idea is simple, but I have a problem: I get MLE of #15, and I can't fix it. I'we tried all ways of graph representation, but I always get MLE #15. Can someone please help me? Here is part of my code that uses the memory, the working part is eliminated: type TEdge=record i,j:integer end; var g:array[1..100001] of TEdge; st,deg:array[0..1001] of integer; sol:array[1..1000] of integer; n,m,i,k:integer; procedure sort(l,r:integer); var i,j:integer; k,t:TEdge; begin i:=l; j:=r; k:=g[(i+j) div 2]; while i<=j do begin while (g[i].i<k.i) or ((g[i].i=k.i) and (g[i].j<k.j)) do inc(i); while (k.i<g[j].i) or ((k.i=g[j].i) and (k.j<g[j].j)) do dec(j); if i<=j then begin t:=g[i]; g[i]:=g[j]; g[j]:=t; inc(i); dec(j) end end; if i<r then sort(i,r); if l<j then sort(l,j) end; begin assign(input,''); reset(input); readln(n,m); for i:=1 to n+1 do begin deg[i]:=0 end; for k:=1 to m do begin readln(g[k].i,g[k].j); inc(deg[g[k].j]) end; g[m+1].j:=0; g[m+1].i:=0; for i:=1 to n do read(sol[i]); sort(1,m); close(input); // working part goes here, cut because of fourth rule..... end. When i first time solution this problem o has WA and really don't understand WHY. But now i write a simple programm 20 lines and get AC. Sorry for my English. Edited by author 01.04.2005 20:05 Very simple... Edited by author 01.04.2005 20:08 Pls dont do any sort, just check for prerequisites of subjects in the left side of order for given subject. I think you should be able to get solution in O(N+M). import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class ba9n { public static void array(String[] shop){ for(int x=0;x < shop.length;x++){ System.out.println(shop[x]); } }
public static void arrayscanner(String[] shop) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for(int x = 0;x < shop.length;x++){ shop[x] = in.readLine(); } }
public static void task(String[] shop){ int answer = 0; for(int x = 0,y = 0;x < shop.length;x++){ if(shop[x] == "-1"){ continue; } for(;y < shop.length;y++){
if (x == y){ continue; } if (shop[x].equals(shop[y]) == true){ answer++; shop[y] = "-1"; } } y = 0; } System.out.println(answer); }
public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in);
int allshops = in.nextInt(); String[] shop = new String[allshops];
arrayscanner(shop); //array(shop); task(shop); } } In my compiller all worked good! I guess that there must be something wrong in the test of system. Execution time is just 0.14 (even less), and Memory used: 2 008 KB My solution: static void Main(string[] args) { char[] chs = Console.In.ReadToEnd().TrimEnd().ToCharArray(); string tmpStr=""; foreach (char ch in chs) { if (char.IsLetter(ch)) { tmpStr = ch + tmpStr; } else { Console.Write(tmpStr+ch); tmpStr = ""; } } if (tmpStr != "") Console.Write(tmpStr); Console.ReadLine(); } Edited by author 26.02.2013 06:18 Edited by author 26.02.2013 06:34 program URAL1299(input,output); var n,np,m,mp,p,x,yg:longint; ch:char; procedure gfire; begin if (abs(yg)>=10)or(m=0) then writeln('FRONT ',x) else writeln( 'FIRE ',p); end; procedure bfire; begin if (abs(yg)>=5)or(m=0) then writeln('BACKWARD ',x) else writeln('FIRE ',p); end; procedure attack; begin readln(n,np); if n*np>=3*m*mp then gfire else bfire; end; procedure guard; begin if m=0 then begin writeln('STOP');exit; end; if abs(yg)<5 then writeln('FIRE ',p) else begin if yg>=+5 then writeln( 'LEFT ',x); if yg<=-5 then writeln('RIGHT ',x); end; end; procedure defense; begin if m*20>=p then bfire else guard; end; procedure patrol; begin readln(yg);//yg:=yg+180; if m>0 then defense else begin if abs(yg)<=20 then writeln('FRONT ',x) else if abs(yg)>=160then writeln('BACKWARD ',x)else begin if yg<-90 then yg:=+180-abs(yg); if yg>+90 then yg:=-180+abs(yg); if yg> 0 then writeln('LEFT ',x) else writeln('RIGHT ',x); end; end; end; begin readln(x,p); if x>100 then x:=100; if p> 20 then p:= 20; readln(ch);readln(m,mp,yg); case ch of 'G':guard; 'A':attack; 'P':patrol; 'D':defense; end; end. >if x>100 then x:=100; >if p> 20 then p:= 20; You have to use initial values, while finding solution. > if n*np>=3*m*mp This has to be n*np>3*m*mp My solution failed on 14th test, because mine was written like: if n*np*3>m*mp
Could you please give me the file of test node #11??? Combo fail: floating-point + division by zero var y,n,m,c,e,f:int64;x,p:integer; begin read(n,m,y); for x:=0 to m-1 do begin f:=trunc(exp(ln(x)*n)); if f mod m = y then inc(p); end; If p=0 then write ('-1'); for x:=0 to m-1 do begin f:=round(exp(ln(x)*n)); if f mod m = y then write (x,' '); end; end. WHY???? test 6 is something like this: 1 1 . answer: 1 1 1 I got TLE 15 times beacuse of this test! hi,friend how to get the damn test data i TLE on test 1 many time Thank you!! You've saved me. :) check your solution for this case: 0 0 1 0 0 1 1 1 answer is -1. How to optimize my code? I know there is a lot of convertions from one type to another. How to avoid it? Or problem of speed not in convertions? import sys, re, math str1 = str(sys.stdin.readlines()) Data = re.findall('\\b\\d+\\b', str1) for i in reversed (Data): print('%.4f' % math.sqrt(float(i))) Edited by author 19.02.2013 23:58 solution, which worktime is 1.85 import sys, re from math import sqrt as sq def find_numbers(f): for line in f: for word in line.split(): if word.isdigit(): yield float(word) lst = list(find_numbers(sys.stdin)) lst.reverse() for x in lst: print('%.4f' % sq(x)) I send my solution for problem 1837 in Java and got this. I used in my program Collections.sort, sun.misc.Queue, HashMap. Can anyone help me? |
|