2026/10/16 1:43:16

18:鸡尾酒疗法

18:鸡尾酒疗法 /** * 题目名称鸡尾酒疗法 p * 题目来源http://noi.openjudge.cn/ch0105/18/ p * 程序功能计算各类改进疗法与鸡尾酒疗法效果比较的结果 * * author 潘磊just_panleijust.edu.cn * version 1.0 */importjava.util.Scanner;publicclassMain{/** * 返回各类改进疗法与鸡尾酒疗法效果比较的结果。 * * param totalCases 各类疗法的总病例数其中第一项为鸡尾酒疗法的总病例数。 * param effectiveCases 各类疗法的有效病例数其中第一项为鸡尾酒疗法的有效病例数。 * param threshold 治疗效果比较的阈值。 * return 各类改进疗法与鸡尾酒疗法效果比较的结果。其中数字1代表当前改进疗法治疗效果好 * 数字-1代表鸡尾酒疗法治疗效果好数字0代表两类疗法治疗效果相同。 */publicint[]compareCures(int[]totalCases,int[]effectiveCases,doublethreshold){intntotalCases.length;// 所有疗法的种类int[]ansnewint[n-1];// 各类改进疗法与鸡尾酒疗法效果比较的结果doublecockTail1.0*effectiveCases[0]/totalCases[0];// 计算鸡尾酒疗法的有效率doublerate;// 当前改进疗法的有效率/* 从第一类改进疗法依次遍历到第n-1类改进疗法 */for(inti1;in;i){rate1.0*effectiveCases[i]/totalCases[i];// 计算当前改进疗法的有效率if(rate-cockTailthreshold){// 如果当前改进疗法治疗效果好ans[i-1]1;// 标记比较结果为数字1}elseif(cockTail-ratethreshold){// 否则如果鸡尾酒疗法治疗效果好ans[i-1]-1;// 标记比较结果为数字-1}else{// 否则两类疗法治疗效果相同ans[i-1]0;// 标记比较结果为数字0}}returnans;}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intninput.nextInt();int[]totalCasesnewint[n];int[]effectiveCasesnewint[n];for(inti0;in;i){totalCases[i]input.nextInt();effectiveCases[i]input.nextInt();}int[]anscall.compareCures(totalCases,effectiveCases,0.05);for(inti0;in-1;i){if(ans[i]1){System.out.println(better);}elseif(ans[i]-1){System.out.println(worse);}else{System.out.println(same);}}}}/** * 题目名称鸡尾酒疗法 p * 题目来源http://noi.openjudge.cn/ch0105/18/ p * 程序功能计算各类改进疗法与鸡尾酒疗法效果比较的结果 * * author 潘磊just_panleijust.edu.cn * version 1.1 */importjava.util.Scanner;publicclassMain{/** * 返回当前改进疗法与鸡尾酒疗法效果比较的结果。 * * param currentCase 当前改进疗法的总病例数。 * param effectiveCase 当前改进疗法的有效病例数。 * param cockTail 鸡尾酒疗法的有效率。 * param threshold 治疗效果比较的阈值。 * return 当前改进疗法与鸡尾酒疗法效果比较的结果。其中数字1代表当前改进疗法治疗效果好 * 数字-1代表鸡尾酒疗法治疗效果好数字0代表两类疗法治疗效果相同。 */publicintcompareCure(intcurrentCase,inteffectiveCase,doublecockTail,doublethreshold){doublerate1.0*effectiveCase/currentCase;// 计算当前改进疗法的有效率if(rate-cockTailthreshold){// 如果当前改进疗法治疗效果好return1;}if(cockTail-ratethreshold){// 否则如果鸡尾酒疗法治疗效果好return-1;}return0;// 否则两类疗法治疗效果相同}publicstaticvoidmain(String[]args){MaincallnewMain();ScannerinputnewScanner(System.in);intninput.nextInt();intcockTailCasesinput.nextInt();intcockTailEffectiveCasesinput.nextInt();doublecockTail1.0*cockTailEffectiveCases/cockTailCases;intcurrentCase;inteffectiveCase;intans;for(inti0;in-1;i){currentCaseinput.nextInt();effectiveCaseinput.nextInt();anscall.compareCure(currentCase,effectiveCase,cockTail,0.05);if(ans1){System.out.println(better);}elseif(ans-1){System.out.println(worse);}else{System.out.println(same);}}}}