Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
同样的算法 我用java 写老是超时 用c++ 写就过了 郁闷啊 谁解释解释#include <cstdlib> #include <iostream> #include <list> using namespace std; int main(int argc, char *argv[]) { int p,e ,i ,d ; list<int> ls ; list<int>::iterator it; int res,k; while(true){ scanf("%d %d %d %d",&p,&e,&i,&d);//输入四个值 if(p==-1&&e==-1 && i==-1 && d==-1){break ;} p = p%23 ; e = e%28 ; i = i%33 ; res = (5544*p+14421*e+1288*i-d+21252)%21252; if(res==0) ls.push_back(res+21252); else ls.push_back(res); } for(it=ls.begin(),k=1;it!=ls.end();it++,k++){ cout<<"Case "<<k<<": the next triple peak occurs in "<<*it<<" days."<<endl; } system("PAUSE"); return EXIT_SUCCESS; } 顺利ac 用java 写 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = ""; List<Integer> list = new LinkedList<Integer>();// 储存的结果 Scanner s = null; try { int p = 0, e = 0, i = 0, d = 0;// 初始值 int res = 0;//结果 while (true) { str = in.readLine();// 从键盘读取一行 s = new Scanner(str); // 对该行进行分割 p = s.nextInt() % 23; e = s.nextInt() % 28; i = s.nextInt() % 33;// 获得初始值 d = s.nextInt(); s.close(); if (p == -1 && e == -1 && i == -1 && d == -1) { in.close(); break; } res = (5544*p+14421*e+1288*i-d+21252)%21252; if(res!=0) list.add(new Integer(res)); else list.add(new Integer(res+21252)); } } catch (IOException v) { v.printStackTrace(); } if (list!= null) for (int i = 0; i<list.size();i++) { System.out.println("Case " + (i + 1) + ": the next triple peak occurs in " + list.get(i).toString() + " days."); } } } 老是超时 郁闷啊 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator