1026 Table Tennis

#include<bits/stdc++.h> 
using namespace std;
const int MAXN=10002;
const int INF=1000000000;
struct Node{
	int start;
	int startwork;
	int time;
	int flag;
	int id;
}node[MAXN];
struct Table{
	int vip;
	int cnt;
	int endtime;
}table[102];
bool cmp(Node a,Node b){
	return a.start<b.start;
}
bool cmp1(Node a,Node b){
	return a.startwork<b.startwork;
}
int main()
{
	freopen("in.txt","r",stdin);
	int n;cin>>n;vector<Node> ppp;
	int sign1[MAXN]={};
	for(int i=0;i<n;i++){
		int h,m,s,t;
		scanf("%d:%d:%d %d %d",&h,&m,&s,&t,&node[i].flag);
		if(t>2*60){
			t=2*60;
		}
		node[i].time=t*60;
		node[i].start=h*3600+m*60+s;
		node[i].id=i;
		if(node[i].flag==1){
			ppp.push_back(node[i]);
		}
	}
	sort(node,node+n,cmp);
	sort(ppp.begin(),ppp.end(),cmp);
	int kk,m;cin>>kk>>m;
	for(int i=1;i<=kk;i++){
		table[i].vip=0;
		table[i].endtime=8*3600;
	}
	for(int i=0;i<m;i++){
		int temp;cin>>temp;
		table[temp].vip=1;
	}
	vector<Node> temp;
	for(int i=0;i<n;i++){
		int k=-1;int MINendtime=INF;
		for(int j=1;j<=kk;j++){
			if(table[j].endtime<MINendtime){
				k=j;
				MINendtime=table[j].endtime;
			}
		}
		if(table[k].endtime<21*3600){
			if(table[k].vip==1){
				if(ppp.size()!=0&&ppp[0].start<=table[k].endtime){
					if(sign1[ppp[0].id]==0){
						sign1[ppp[0].id]=1;
						ppp[0].startwork=table[k].endtime;
						table[k].endtime+=ppp[0].time;table[k].cnt++;
						temp.push_back(ppp[0]);
						ppp.erase(ppp.begin());	
					}else{
						ppp.erase(ppp.begin());
					}
					i--;	
				}else{
					if(sign1[node[i].id]==0){
						sign1[node[i].id]=1;
						if(node[i].start<=table[k].endtime){
							node[i].startwork=table[k].endtime;
							table[k].endtime+=node[i].time;table[k].cnt++;
							temp.push_back(node[i]);
						}else{
							node[i].startwork=node[i].start;
							table[k].endtime=node[i].start+node[i].time;table[k].cnt++;
							temp.push_back(node[i]);
						}
					}else{
						continue;
					}
				}
			}else{
				if(sign1[node[i].id]==0){
					sign1[node[i].id]=1;
					if(node[i].start<=table[k].endtime){
						node[i].startwork=table[k].endtime;
						table[k].endtime+=node[i].time;table[k].cnt++;
						temp.push_back(node[i]);
					}else{
						node[i].startwork=node[i].start;
						table[k].endtime=node[i].start+node[i].time;table[k].cnt++;
						temp.push_back(node[i]);
					}
				}else{
					continue;
				}
			}
		}
	}
	sort(temp.begin(),temp.end(),cmp1);
	for(int i=0;i<temp.size();i++){
		int h1,m1,s1,h2,m2,s2,wt;
		h1=temp[i].start/3600;m1=temp[i].start%3600/60;s1=temp[i].start%3600%60;
		h2=temp[i].startwork/3600;m2=temp[i].startwork%3600/60;s2=temp[i].startwork%3600%60;
		wt=temp[i].startwork-temp[i].start;
		if(wt%60!=0){
			wt=wt/60+1;
		}else{
			wt=wt/60;
		}
		printf("%02d:%02d:%02d %02d:%02d:%02d %d\n",h1,m1,s1,h2,m2,s2,wt);
	}
	for(int i=1;i<=kk;i++){
		if(i==1) cout<<table[i].cnt;
		else cout<<' '<<table[i].cnt;
	}
	return 0;
}

23分飘过,待修改。。。

The following is the data that you can add to your input file (as an example). Notice that the first line is going to be a line representing your own hobbies. In my case, it is the Vitaly,table tennis,chess,hacking line. Your goal is to create a class called Student. Every Student will contain a name (String) and an ArrayList<String> storing hobbies. Then, you will add all those students from the file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here is an example file containing students (the first line will always represent yourself). NOTE: eventually, we will have a different file containing all our real names and hobbies so that we could find out with how many people each of us share the same hobby. Vitaly,table tennis,chess,hacking Sean,cooking,guitar,rainbow six Nolan,gym,piano,reading,video games Jack,cooking,swimming,music Ray,piano,video games,volleyball Emily,crochet,drawing,gardening,tuba,violin Hudson,anime,video games,trumpet Matt,piano,Reading,video games,traveling Alex,swimming,video games,saxophone Roman,piano,dancing,art Teddy,chess,lifting,swimming Sarah,baking,reading,singing,theatre Maya,violin,knitting,reading,billiards Amy,art,gaming,guitar,table tennis Daniel,video games,tennis,soccer,biking,trumpet Derek,cooking,flute,gaming,swimming,table tennis Daisey,video games,guitar,cleaning,drawing,animated shows,reading,shopping Lily,flute,ocarina,video games,baking Stella,roller skating,sudoku,watching baseball,harp Sophie,viola,ukulele,piano,video games
06-10
I understand that you want me to create a class called Student and add all the students from the given file into an ArrayList<Student>, with each Student having a separate name and ArrayList of hobbies. Here's the code to achieve the same: ``` import java.io.*; import java.util.*; class Student { private String name; private ArrayList<String> hobbies; public Student(String name, ArrayList<String> hobbies) { this.name = name; this.hobbies = hobbies; } public String getName() { return name; } public ArrayList<String> getHobbies() { return hobbies; } } public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new File("students.txt")); String[] firstLine = scanner.nextLine().split(","); String myName = firstLine[0]; ArrayList<String> myHobbies = new ArrayList<>(Arrays.asList(Arrays.copyOfRange(firstLine, 1, firstLine.length))); ArrayList<Student> students = new ArrayList<>(); students.add(new Student(myName, myHobbies)); while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split(","); String name = line[0]; ArrayList<String> hobbies = new ArrayList<>(Arrays.asList(Arrays.copyOfRange(line, 1, line.length))); students.add(new Student(name, hobbies)); } scanner.close(); // Now, the students ArrayList contains all the students with their respective names and hobbies // You can use this ArrayList to perform any further operations as needed } } ``` You can replace "students.txt" with the name of your input file containing the student data. Let me know if you have any further questions.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值