The 11th Zhejiang Provincial Collegiate Programming Contest

C: Talented Chef   ZOJ  3778
题目大意:一共有n道菜,每道菜需要ai步,每次最多同时做m道菜,问最后做完所有的菜,需要的最少的时间。
思路:将n道菜的所有步骤进行加和,比较 sum/m + sum%m  与maxn 之间的关系,取两者之间的较大的值。

题目思路:贪心。参考来源
①当n <= m : 令n道菜每次减少1,所以次数为maxn(最多步骤的那道菜)

②当n > m考虑两种情况:

     1、每次如果恰好使得m个数-1.那么次数为sum / m。如果最后一次不是m个数,则需 + 1
       eg : 1 2 3 4 5 6 7 8 9 10
    
     2、如果未取到最后一次,需要做的菜 < m,则 结果为 maxn(最多步骤的那道菜)
     eg: 1 1 1 1 1 1 1 1 1 10    
    


代码:

#include <bits/stdc++.h>
using namespace std;
int num[40005];
int main(){
    int t;
    cin >> t;
    while(t--){
        int n,m,sum = 0,maxn = 0;
        cin >> n >> m;
        for (int i = 0; i < n; i++){
            cin >> num[i];
            maxn = max(maxn,num[i]);
            sum += num[i];
        }
        int ret = sum / m;
        if (sum % m) ret++;
        cout << max(ret,maxn) << endl;      
    }   
    return 0;
}


J:What day is that day?    ZOJ 3785
题目大意:从星期六开始计算,给定一个数字n,问过了1^1 + 2^2 + 3^3 + ... + N^N 到了星期几。
思路:由于n的范围太大,这显然是存在周期的(但没想着周期竟然有294这么大)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int s[295];
char st[10][12] = {"Saturday","Sunday","Monday","Tuesday","Wednesday","Thursday","Friday"};
int work(int n){
    int num = 1;
    for(int i = 1;i<=n;i++){
        num = num*n;
        num = num%7;
    }
    return num;
}
void init(){
    s[0] = 0;
    for(int i = 1;i<295;i++){
        s[i] = s[i-1]+work(i);
        s[i] = s[i]%7;
    }
}
int main(){
    init();
    int t, n;
    scanf("%d",&t);
    while(t--){
        scanf("%d",&n);
        n = n%294;
        printf("%s\n",st[s[n]]);
    }
    return 0;
}

G: Ternary Calculation     ZOJ 3782
题目大意:给定两个符号,三个数字。计算最后结果。乘除模优先级相同,结合顺序为从左向右。(暴力-_-)
 

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
using namespace std;
int main(){
    char ch1,ch2;
    int a,b,c;
    int t;
    scanf("%d",&t);
    while(t--){
        scanf("%d %c %d %c %d",&a,&ch1,&b,&ch2,&c);
        if(ch1=='+'||ch1=='-'){
            int ans;
            if(ch2=='+') ans=b+c;
            else if(ch2=='-') ans=b-c;
            else if(ch2=='*') ans=b*c;
            else if(ch2=='/') ans=b/c;
            else ans=b%c;

            if(ch1=='+') printf("%d\n",ans+a);
            else{
                if(ch2=='-') printf("%d\n",a-b-c);//因为ch1是减号,若ch2是加或者是减,不可以直接用a-ans
                                                //假设ch2为加号a-ans=a-(b+c),实际结果你应该是a-b+c
                else if(ch2=='+') printf("%d\n",a-b+c);
                else printf("%d\n",a-ans);
            }
            //else printf("%d\n",a-ans);
        }
        else{
            int ans;
            if(ch1=='*') ans=a*b;
            else if(ch1=='/') ans=a/b;
            else if(ch1=='%') ans=a%b;

            if(ch2=='+') printf("%d\n",ans+c);
            else if(ch2=='-') printf("%d\n",ans-c);
            else if(ch2=='*') printf("%d\n",ans*c);
            else if(ch2=='/') printf("%d\n",ans/c);
            else printf("%d\n",ans%c);
        }
    }
    return 0;
}

L: Access System    ZOJ  3787
题目大意:有n个学生,接下来是他们回宿舍的时间,当某一位学生打开宿舍门后,在这L秒内(不包括第L秒)进入宿舍的学生不需要开门,问这n个学生进入宿舍,需要开门多少次。
思路:给的时间包括时分秒,所以可以把时间都转化为秒的形式进行比较。从小到大进行排序,从第i位同学开始,用t代替此刻的时间,碰到i后第一个间隔小于L的时间j,就让sum加1,同时令t等于j位置对应的时间。sum的初始值为1。
代码:
 

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int f[20010];
struct node{
    int num,cnt;
}p[20010];
int cmp(node a,node b){
      return a.num<b.num;
}
int cmp1(int a,int b){
    return a<b;
}
int main(){
     int T;
     int n,m;
     int shi,fen,miao;
     while(scanf("%d",&T)!=EOF){
        while(T--){
            cin>>n>>m;
            for(int i=1;i<=n;i++){
                scanf("%d:%d:%d",&shi,&fen,&miao);
                p[i].cnt=i;//存下标
                p[i].num=shi*60*60+fen*60+miao;//存时间
            }
            sort(p+1,p+n+1,cmp);
            int sum=0;
            int x=p[1].num;
            f[0]=p[1].cnt;
            int ant=1;
            for(int i=2;i<=n;i++){

                if(p[i].num-x>=m){
                    sum++;
                    f[ant++]=p[i].cnt;
                    x=p[i].num;
                }
            }
            cout<<sum<<endl;
            sort(f,f+ant,cmp1);
            for(int i=0;i<ant-1;i++)
            {
                printf("%d ",f[i]);
            }
            cout<<f[ant-1]<<endl;
        }
     }

    return 0;

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值