// initializes the object, asking for the x and y component of it Vector() { Scanner scans = new Scanner(System.in); float vx = scans.nextFloat(); float vy = scans.nextFloat(); this.vx = vx; this.vy = vy; }
public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); int test = scan.nextInt(); double limit; while (test-- > 0) { limit = scan.nextDouble(); n = scan.nextInt(); V = 0; mm = new int[n]; pp = new float[n]; for (int i = 0; i < n; i++) { mm[i] = scan.nextInt(); pp[i] = scan.nextFloat(); V += mm[i]; } dp = new float[V + 1]; Arrays.fill(dp, 0); dp[0] = 1; for (int i = 0; i < n; i++) ZeroPack(mm[i], 1 - pp[i]); for (int i = V; i >= 0; i--) if (dp[i] > 1 - limit) { out.println(i); break; } } out.flush(); out.close(); }
/*takes a vector, then multiplies it by the inputted scalar asked for at the beginning of the instance method*/ void scalarProduct() { System.out.println("Enter scalar multiple:"); Scanner scanner = new Scanner(System.in); float constant = scanner.nextFloat(); float scalarx = constant * vx; float scalary = constant * vy; System.out.printf("\nScalar Product: (%.2f, %.2f)\n", scalarx, scalary); }
public void loadView(String filename) { Point3 point; Vector3 tvec; double radius; double azimuth; double elevation; double scale; double x, y, z; double vx, vy, vz; try { if (_ipg == null) throw new Exception("Must load a cube first!"); Scanner s = new Scanner(new File(filename)); radius = s.nextDouble(); x = s.nextDouble(); y = s.nextDouble(); z = s.nextDouble(); point = new Point3(x, y, z); azimuth = s.nextDouble(); elevation = s.nextDouble(); scale = s.nextDouble(); vx = s.nextDouble(); vy = s.nextDouble(); vz = s.nextDouble(); tvec = new Vector3(vx, vy, vz); Iterator<ImagePanel> itr = _ipg.getImagePanels(); while (itr.hasNext()) { ImagePanel ip = itr.next(); AxisAlignedFrame aaf = ip.getFrame(); double lx = s.nextDouble(); double ly = s.nextDouble(); double lz = s.nextDouble(); double mx = s.nextDouble(); double my = s.nextDouble(); double mz = s.nextDouble(); Point3 min = new Point3(lx, ly, lz); Point3 max = new Point3(mx, my, mz); aaf.setCorners(min, max); } _pmax = s.nextFloat(); int code = s.nextInt(); _color = ColorList.getMatch(code); setColorMap(); _view.setWorldSphere(new BoundingSphere(point, radius)); _view.setTranslate(tvec); _view.setAzimuth(azimuth); _view.setElevation(elevation); _view.setScale(scale); _ipg.setPercentiles(_pmin, _pmax); } catch (Exception e) { System.out.println("Failed to load view point!"); System.out.println(e); } }
public static void main(String[] args) throws IOException { int n; int u, v; float c; String line; Scanner s = new Scanner(System.in); File f = new File("vertices.txt"); Scanner scan = new Scanner(f.getAbsoluteFile()); n = scan.nextInt(); System.out.println("The number of vertices= " + n); CPP obj = new CPP(n); // Closed Chinese Postman Tour OpenCPP ob = new OpenCPP(n); // Open Chinese Postman Tour File fi1 = new File("label.txt"); File fi2 = new File("from.txt"); File fi3 = new File("to.txt"); File fi4 = new File("cost.txt"); FileReader in1 = new FileReader(fi1.getAbsolutePath()); FileReader in2 = new FileReader(fi2.getAbsolutePath()); FileReader in3 = new FileReader(fi3.getAbsolutePath()); FileReader in4 = new FileReader(fi4.getAbsolutePath()); Scanner scan1 = new Scanner(in1); Scanner scan2 = new Scanner(in2); Scanner scan3 = new Scanner(in3); Scanner scan4 = new Scanner(in4); File fi1o = new File("labelopen.txt"); File fi2o = new File("fromopen.txt"); File fi3o = new File("toopen.txt"); File fi4o = new File("costopen.txt"); FileReader in1o = new FileReader(fi1o.getAbsolutePath()); FileReader in2o = new FileReader(fi2o.getAbsolutePath()); FileReader in3o = new FileReader(fi3o.getAbsolutePath()); FileReader in4o = new FileReader(fi4o.getAbsolutePath()); Scanner scan1o = new Scanner(in1o); Scanner scan2o = new Scanner(in2o); Scanner scan3o = new Scanner(in3o); Scanner scan4o = new Scanner(in4o); long start = System.nanoTime(); do { line = scan1.nextLine(); u = scan2.nextInt(); v = scan3.nextInt(); c = scan4.nextFloat(); obj.addArc(line, u - 1, v - 1, c); } while (scan2.hasNext() && scan1.hasNext() && scan3.hasNext() && scan4.hasNext()); obj.solve(); obj.printCPT(0); System.out.println("Cost= " + obj.cost()); do { line = scan1o.nextLine(); u = scan2o.nextInt(); v = scan3o.nextInt(); c = scan4o.nextFloat(); ob.addArc(line, u - 1, v - 1, c); } while (scan2o.hasNext() && scan1o.hasNext() && scan3o.hasNext() && scan4o.hasNext()); float x; x = ob.printCPT(1); System.out.println("Cost= " + x); long Time = System.nanoTime() - start; double timeInSeconds = Time / 1e9; System.out.println("Elapsed time: " + timeInSeconds); }
public static boolean generateTrainingFile( String sensorDataFolder, String sensorDataFile, String sensorMarksFolder, String sensorMarksFile, String outFolder, String outFile, Context context) { IWindowData windowData = new WindowHalfOverlap(128); IFeatures myFeatures = new MyFeatures(); Scanner scanSD = null, scanSM = null; File sensorData = MyUtil.getSDFile(sensorDataFolder, sensorDataFile); File sensorMarks = MyUtil.getSDFile(sensorMarksFolder, sensorMarksFile); try { scanSD = new Scanner(sensorData); scanSD.useLocale(Locale.US); } catch (FileNotFoundException e1) { return false; } try { scanSM = new Scanner(sensorMarks); scanSM.useLocale(Locale.US); } catch (FileNotFoundException e1) { scanSD.close(); return false; } // progress bar int total = getNumberOfLines(sensorData); /* int total = 0; float mean = 0; boolean correct = getNumberOfLines(sensorData, total, mean); if(!correct){ scanSM.close(); scanSD.close(); return false; } Intent intent = new Intent("com.example.activityregistrator.UPDATE_HZ"); intent.putExtra("hz", 1/mean); context.sendBroadcast(intent); */ float done = 0; Long prevTimeSM, postTimeSM, timeSD = -1l, lastTimeSD = 0l, firstTimeSD = -1l; int prevLabel, postLabel; if (scanSM.hasNextLine()) { scanSM.nextLine(); prevTimeSM = scanSM.nextLong(); prevLabel = scanSM.nextInt(); scanSD.nextLine(); Intent intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS"); intent.putExtra("progress", (float) ((++done) / total) * 100); context.sendBroadcast(intent); // find next time and label while (scanSM.hasNextLine()) { scanSM.nextLine(); if (!scanSM.hasNextLong()) break; Log.d(TAG, "prevTimeSM: " + prevTimeSM + "; prevLabel: " + prevLabel); postTimeSM = scanSM.nextLong(); postLabel = scanSM.nextInt(); Log.d(TAG, "postTimeSM: " + postTimeSM + "; postLabel: " + postLabel); // each window has unique label windowData.clean(); // search windowData beginning // assumption: register only label>0 --> IGNORE<=0 while (prevLabel > 0) { if (timeSD < 0) { if (!scanSD.hasNextLong()) { break; } timeSD = scanSD.nextLong(); } // used to calculate hz lastTimeSD = timeSD; if (firstTimeSD < 0) firstTimeSD = timeSD; if (timeSD >= prevTimeSM) { if (timeSD <= postTimeSM) { Log.d(TAG, "timeSD: " + timeSD); // add x y z to windowData float[] linearAccel = {scanSD.nextFloat(), scanSD.nextFloat(), scanSD.nextFloat()}; if (windowData.addData((float) vecLength(linearAccel))) { // we have a complete windowData // calculate features float[] features = myFeatures.getFeatures(windowData); // save to libsvm file with the correct label String[] textToFile = new String[1]; textToFile[0] = prevLabel + " "; for (int i = 0; i < features.length; i++) { textToFile[0] += (i + 1) + ":" + features[i] + " "; } MyUtil.writeToSDFile(textToFile, outFolder, outFile, true); } if (scanSD.hasNextLine()) { scanSD.nextLine(); intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS"); intent.putExtra("progress", (float) ((++done) / total) * 100); context.sendBroadcast(intent); timeSD = -1l; // get nextLong() } else { break; } } else { break; } } else { if (scanSD.hasNextLine()) { scanSD.nextLine(); intent = new Intent("com.example.activityregistrator.UPDATE_PROGRESS"); intent.putExtra("progress", (float) ((++done) / total) * 100); context.sendBroadcast(intent); timeSD = -1l; // get nextLong() } else { break; } } } prevTimeSM = postTimeSM; prevLabel = postLabel; } } scanSD.close(); scanSM.close(); Intent intent = new Intent("com.example.activityregistrator.UPDATE_HZ"); intent.putExtra("hz", done / (((float) (lastTimeSD - firstTimeSD)) / 1000f)); context.sendBroadcast(intent); Log.d(TAG, "[firstTimeSD,lastTimeSD,done]: " + firstTimeSD + " " + lastTimeSD + " " + done); return true; }