Общий форумIs there somewhere a list with the restricted functions for Java? B can be greater than A Good Luck ^^ N'Pong Thx for your hint. from P'Moo Edited by author 07.01.2007 11:30 Thx a lot! but why goods at moderate price cost higher than "high price" good? I don't care for value of b :) What I must print if sample input 1 5 1 2 3 4 5 Give me some hints please you can use dynamic programming Please, tell me how to dp? I just use a heap. Edited by author 18.08.2006 19:22 Sort by finish time. For every delivery do: if current delivery time is greater than the number of already scheduled deliveries, schedule it; else (that is, it is equal), replace the least important scheduled delivery with this one. Altogether O(n log(n)). Edited by author 10.03.2010 18:40 Edited by author 10.03.2010 18:40 13?? why。。。。 #include<iostream> using namespace std; struct Point { char Name[50]; int Price,Value; }P[101]; int N,M; unsigned long long Ans=(unsigned long long)1<<63; long long DP[40010]; int Num[40010]; int Pre[40010]; int Sel[40010]; int Hash[101]; int main() { scanf("%d%d\n",&N,&M); M=M*1000; for(int i=1;i<=N;i++) { double Tmp; scanf("%s %d %lf",&P[i].Name,&P[i].Price,&Tmp); P[i].Value=int(Tmp*1000+0.0001); } DP[0]=1; for(int i=1;i<=N;i++) for(int j=0;j<=M;j++) if(DP[j]) { if(DP[j+P[i].Value]==0) { DP[j+P[i].Value]=DP[j]+P[i].Price; Pre[j+P[i].Value]=j; Sel[j+P[i].Value]=i; if(i==Sel[j]) Num[j+P[i].Value]=Num[j]; else Num[j+P[i].Value]=Num[j]+1; } else if(DP[j+P[i].Value]>DP[j]+P[i].Price) { DP[j+P[i].Value]=DP[j]+P[i].Price; Pre[j+P[i].Value]=j; Sel[j+P[i].Value]=i; if(i==Sel[j]) Num[j+P[i].Value]=Num[j]; else Num[j+P[i].Value]=Num[j]+1; } else if(DP[j+P[i].Value]==DP[j]+P[i].Price) { if(i==Sel[j]) { if(Num[j+P[i].Value]<Num[j]) { Pre[j+P[i].Value]=j; Sel[j+P[i].Value]=i; Num[j+P[i].Value]=Num[j]; } } else if(Num[j+P[i].Value]<=Num[j]+1) { Pre[j+P[i].Value]=j; Sel[j+P[i].Value]=i; Num[j+P[i].Value]=Num[j]+1; } } } int TT; for(int i=M;i<=M+20000;i++) if(DP[i]&&DP[i]<Ans) Ans=DP[i],TT=i; else if(DP[i]&&DP[i]==Ans&&Num[i]>Num[TT]) Ans=DP[i],TT=i; cout<<Ans-1<<endl; while(TT>=1) { Hash[Sel[TT]]++; TT=Pre[TT]; } for(int i=1;i<=N;i++) if(Hash[i]) printf("%s %d\n",P[i].Name,Hash[i]); return 0; } Edited by author 10.03.2010 13:51 For "newagent" event: new agent coming to the organization with experience not less than retirement experience. It is not contradict the problem statement but can be misleading. To get right solution just ignore the fact that agent has come already tired. ...fixed by Admins? Edited by author 09.03.2010 11:22 another statement bug: "All other numbers are positive integers and do not exceed 10^6" but current distance passed for car equals to 0 (Test #1, #2) so: some numbers are not positive but not negative... Edited by author 12.03.2010 12:18 this my code: import java.io.*; import java.util.*; public class Problem_1147 implements Runnable{ public static void main(String []args){ new Thread(new Problem_1147()).start(); } public void run(){ try{ reader = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); //reader = new StreamTokenizer(new BufferedReader(new FileReader("card.out"))); //out = new PrintWriter(new FileWriter("card.out")); solve(); }catch(IOException e){ throw new IllegalStateException(e); } }
final int COLOR_COUNT = 5501; final int N = 400001; int n; int width; int height;
int xPos[] = new int[10001]; int yPos[] = new int[10001];
int color[] = new int[COLOR_COUNT]; int x[] = new int[1001]; int y[] = new int[1001]; int z[] = new int[1001]; int t[] = new int[1001]; int cc[] = new int[1001]; int xc[] = new int[1009]; int yc[] = new int[1009];
short tColor[][] = new short[2002][2002];
StreamTokenizer reader;
PrintWriter out;
int nextInt()throws IOException{ reader.nextToken(); return(int)reader.nval;
}
void solve()throws IOException{
width = nextInt(); height = nextInt(); n = nextInt();
for (int i = 1; i<=n;i++){ x[i] = nextInt(); y[i] = nextInt(); z[i] = nextInt(); t[i] = nextInt();
cc[i] = nextInt(); } x[0] = 0; y[0] = 0; z[0] = width; t[0] = height; cc[0] = 1;
Arrays.fill(xPos,0); Arrays.fill(yPos,0);
for (int i = 0;i <=n ;i++)xPos[x[i]] = xPos[z[i]] = yPos[y[i]] = yPos[t[i]] = 1;
for (int i = 1; i<= width; i++)xPos[i] += xPos[i-1]; for (int i = 1; i<= height; i++)yPos[i] += yPos[i-1];
for (int i = width; i >= 0 ; i-- ) xc[xPos[i]] = i ; for (int i = height; i>= 0 ; i-- ) yc[yPos[i]] = i ;
/* System.out.println("x coords "); for (int i = xPos[0] ; i<=xPos[width];i++)System.out.println(xc[i]); System.out.println("y coords "); for (int i = yPos[0] ; i<=yPos[height];i++)System.out.println(yc[i]); */ for (int i = 0; i<=n;i++){ int i_x = xPos[x[i]]; int j_x = xPos[z[i]]; int i_y = yPos[y[i]]; int j_y = yPos[t[i]]; short c = (short)cc[i]; // System.out.println(i_x +" " +j_x+" " +i_y+" " +j_y); for (int v = i_x; v < j_x; v++){ for (int w = i_y; w < j_y; w++){ tColor[v][w] = c; } } }
Arrays.fill(color, 0); for (int i = xPos[0]; i < xPos[width]; i++){ for (int j = yPos[0]; j < yPos[height]; j++){ color[tColor[i][j]] += (xc[i+1] - xc[i])*(yc[j+1] - yc[j]); } }
for (int i = 1; i<=2500;i++)if (color[i]>0)System.out.println(i+ " "+color[i]); }
} var i,j,k,l,m:longint; n:qword; a:array[1..10000000]of qword; q:double; begin n:=0; while not eof do begin inc(n); read(a[n]); end; for i:=n-1 downto 1do begin writeln(sqrt(a[i]):0:4); end; end. I finally found where I did wrong... var i,j,k,l,m:longint; n:qword; a:array[1..10000000]of qword; q:double; begin n:=0; while not seekeof do begin inc(n); read(a[n]); end; for i:=n downto 1do begin writeln(sqrt(a[i]):0:4); end; end. should use "seekeof" instead of "eof" What answer for this test? 0 0 8 0 2 0 4 0 6 0 Answer: 8 Thank you, and what answers for this test? 3 1 1 4 4 0 3 3 3 3 0 0 0 0 4 2 1 0 2 2 3 0 0 0 4 0 2 2 2 3 2 I've tried to solve this problem, using simple aproach, only one array in which i remember time until that part of the memory is allocated. On request I check if it's used, if is shift time to new value if not nothing change... On new allocation I search for the first free memory spot... Very simple, straight from the text, but I get WA on #4. Could someone post some tricky test or explain why my algorithm is wrong? Thank you very much! I wouldn't say that it was very easy, but I got AC and learn new way of programming. Try this test: 64999 + 65000 . 1 --------- 1 + I don't know how to correct my program for more speedly work. Help anybody. import java.util.*; import java.math.*; public class InvertedSqrt { public static void main(String []args) { Scanner scan = new Scanner(System.in); ArrayList<BigInteger> input = new ArrayList<BigInteger>(); input.add(scan.nextBigInteger()); while(scan.hasNextBigDecimal() && input.size() * Integer.SIZE <= 256 * 1024 * 1024) { input.add(scan.nextBigInteger()); } scan.close(); int i = input.size() - 1; while(i >=0) { System.out.printf("%.4f",java.lang.Math.sqrt(input.get(i).doubleValue())); System.out.print("\n"); i--; } } } in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); out = new PrintWriter(new OutputStreamWriter(System.out)); I don't know how to correct my program for more speedly work. Help anybody. import java.util.*; import java.math.*; public class InvertedSqrt { public static void main(String []args) { Scanner scan = new Scanner(System.in); ArrayList<BigInteger> input = new ArrayList<BigInteger>(); input.add(scan.nextBigInteger()); while(scan.hasNextBigDecimal() && input.size() * Integer.SIZE <= 256 * 1024 * 1024) { input.add(scan.nextBigInteger()); } scan.close(); int i = input.size() - 1; while(i >=0) { System.out.printf("%.4f",java.lang.Math.sqrt(input.get(i).doubleValue())); System.out.print("\n"); i--; } } } use double, but not BigInteger Hi. I'm using :) such a construction in my code struct maxY { bool operator () (const int& n1, const int& n2) { // compare something } }; ... set<int, maxY> s; in my VS 2009 it's ok, but Online Judge says it's a compilation error. Help to fix, please. Oh, yeah, thanks :) Any other thoughts? I've got, what's the problem. bool operator()(int t1, int t2)const { ... } should be written I have WA 3. what should i output for this test? 2 1 1.000000000001 0 0 0 0 0 0 0 0 -1 0 0 Please add the following test: N=100, the following 10000 numbers -127. Awhile there is no test where answer is negative. Thank you. New tests were added, and many authors lost AC. In this problem,rounding the double value to the nearest integer appeares to be the most tricky part of the whole problem. If you want to guarantee correct rounding, do it yourself with floor() and ceil(). At least,as it happened to me.:) You can do it like this: printf("%.0lf\n", res); You are absolutely right: ``cout << int(r)'' is WA, while ``printf("Distance is %.0lf km.", r);'' is AC. Edited by author 14.05.2010 21:41 Just change longint into int64. Oh,my god! Don't the author say all values are longint? It is not necessary a rectangle. Try 5 11111 11011 11011 10010 00000 Yes and all its rotations. BTW, to read you can use #define F(i,n) for(int i = 0; i < n; ++i) int n; vector<string> s; [...] cin >> n; s.resize(n, string(n,' ')); F(i,n) cin >> s[i]; and AC at 0.046 second. ... whereas F(i,n) { string str; cin >> str; s.push_back(str); } results in 0.109 seconds and 500 KB of wasted memory. I always crash on that test...float point wrong |
|