跳到正文

个人记录

111

xiezhiheng约 10 分钟
原文
文章信息与版本

文章信息

收录
2026年6月29日
更新
2026年6月29日
篇幅
约 10 分钟
获赞
1

版本

  1. v1当前
C++
#include<bits/stdc++.h>
using namespace std;
inline int read(){//快读
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    return x*f;
}
struct node1{//事件
    string name;//名字
    int time;//耗时
    int jing_li;//精力的消耗值
    int zhong_yao_xing;//重要性,越高表示越重要
    int jin_ji_xing;//紧急性,越高表示越紧急
    inline bool operator < (const node1 &q){//比较,决定做事的先后顺序
        if(q.zhong_yao_xing==zhong_yao_xing) return q.jin_ji_xing<jin_ji_xing;
        return q.zhong_yao_xing<zhong_yao_xing;
    }
}gong_zuo[10005];//工作
struct node2{//事件
    string name;//名字
    int time;//耗时
    int jing_li;//精力的回复值
    int cheng_yin_xing;//成瘾性,对工作效率有影响
    inline bool operator < (const node2 &q){//比较,决定做事的先后顺序
        return q.cheng_yin_xing<cheng_yin_xing;
    }
}yu_le[10005];//娱乐
struct node3{
    string name[100005];//名字
    int step;//做了几件事
    int sum_cheng_yin_xing;//成瘾性的总值
    int sum_zhong_yao_xing;//重要性的总值
    inline bool operator < (const node3 &q){
        if(q.sum_cheng_yin_xing==sum_cheng_yin_xing) return step<q.step; 
        return q.sum_cheng_yin_xing<sum_cheng_yin_xing;
    }
}a[15];//最优的三种方案
string name[100005];//名字
int jing_li_max=10000;//精力上限
int all_gong_zuo;//工作总数
int all_yu_le;//娱乐总数
int sleep_end,sleep_begin;//起床与上床时间
inline void readsleep(){
    cout<<"请输入您的起床与上床时间"<<endl;
    cout<<"起床时间:";
	int x=read(),y=read();
	sleep_end=x*60+y;
    system("cls");
    cout<<"上床时间:";
	x=read(),y=read();
	sleep_begin=x*60+y;
    system("cls");
}
inline void check(int step,int sum_cheng_yin_xing,int sum_zhong_yao_xing){//判断是否有更优答案
    //做了几件事、成瘾性的总值与重要性的总值
    if(sum_zhong_yao_xing>a[1].sum_zhong_yao_xing){
        node3 tmp;
        for(int i=1;i<=100004;i++){
            tmp.name[i]=name[i];
        }
        tmp.step=step;
        tmp.sum_cheng_yin_xing=sum_cheng_yin_xing;
        tmp.sum_zhong_yao_xing=sum_zhong_yao_xing;
        a[1]=tmp;
        sort(a+1,a+4);
        return;
    }
    if((sum_zhong_yao_xing==a[1].sum_zhong_yao_xing)&&(sum_cheng_yin_xing<a[1].sum_cheng_yin_xing)){
        node3 tmp;
        for(int i=1;i<=100004;i++){
            tmp.name[i]=name[i];
        }
        tmp.step=step;
        tmp.sum_cheng_yin_xing=sum_cheng_yin_xing;
        tmp.sum_zhong_yao_xing=sum_zhong_yao_xing;
        a[1]=tmp;
        sort(a+1,a+4);
        return;
    }
    if((sum_zhong_yao_xing==a[1].sum_zhong_yao_xing)&&(sum_cheng_yin_xing==a[1].sum_cheng_yin_xing)&&(step<a[1].step)){
        node3 tmp;
        for(int i=1;i<=100004;i++){
            tmp.name[i]=name[i];
        }
        tmp.step=step;
        tmp.sum_cheng_yin_xing=sum_cheng_yin_xing;
        tmp.sum_zhong_yao_xing=sum_zhong_yao_xing;
        a[1]=tmp;
        sort(a+1,a+4);
        return;
    }
}
inline void dfs(int step,int time,int jing_li,int sum_cheng_yin_xing,int sum_zhong_yao_xing){//搜索
	//目前进行了几件事与目前的时间与精力与成瘾性的总值与重要性的总值
    if(time>1440||time>sleep_begin){
        check(step,sum_cheng_yin_xing,sum_zhong_yao_xing);//判断是否有更优答案
        return;
    }
    for(int i=1;i<=all_gong_zuo;i++){//枚举
        if(jing_li>=gong_zuo[i].jing_li){
            name[step+1]=gong_zuo[i].name;
            dfs(step+1,time+gong_zuo[i].time*(1+1.0*sum_cheng_yin_xing/1000),jing_li-gong_zuo[i].jing_li,1.0*sum_cheng_yin_xing*0.9,sum_zhong_yao_xing+gong_zuo[i].zhong_yao_xing);
            //做工作
        }
    }
    for(int i=1;i<=all_yu_le;i++){//枚举
        if(jing_li_max<=jing_li+yu_le[i].jing_li){
            name[step+1]=yu_le[i].name;
            dfs(step+1,time+yu_le[i].time,jing_li+yu_le[i].jing_li,sum_cheng_yin_xing+yu_le[i].cheng_yin_xing,sum_zhong_yao_xing);
            //做娱乐
        }
    }
    dfs(step,time+1,max(jing_li+1,jing_li_max),sum_cheng_yin_xing,sum_zhong_yao_xing);//啥也不做
}
int main(){
    readsleep();
    cout<<"请输入您有几件事:"; 
    int n=read();
    system("cls");
    for(int i=1;i<=n;i++){
    	cout<<"请输入您的第"<<i<<"件事"<<endl; 
    	cout<<"请输入您的第"<<i<<"件事的名字:"; 
        string s;cin>>s;//名字
        cout<<endl<<"请输入您的第"<<i<<"件事是工作或娱乐,工作输入1,娱乐输入2:"<<endl; 
        int pd=read();//判断是工作还是娱乐
        if(pd==1){
        	cout<<"请输入耗时、精力的消耗值、重要性与紧急性"<<endl;
            int a=read(),b=read(),c=read(),d=read();
            gong_zuo[++all_gong_zuo]={s,a,b,c,d};
        }else{
        	cout<<"请输入耗时、精力的回复值与成瘾性"<<endl;
            int a=read(),b=read(),c=read();
            yu_le[++all_yu_le]={s,a,b,c};
        }
        system("cls");
    }
    sort(gong_zuo+1,gong_zuo+all_gong_zuo+1);
    sort(yu_le+1,yu_le+all_yu_le+1);
    dfs(0,sleep_end,10000,0,0);
    cout<<"现在有您的三种最优方案"<<endl;
    for(int i=3;i>=1;i--){
        cout<<"第"<<3-i+1<<"种方案"<<endl;
        for(int j=1;j<=a[i].step;j++){
            cout<<"第"<<j<<"件事:"<<a[i].name[j]<<endl;
        }
        cout<<endl;
    }
    return 0;
}
原文