Practice_17_01_GID

G_今年暑假不AC

  假设已经知道了所有你喜欢看的电视节目的转播时间表,要求能看尽量多的完整节目,返回节目数

  Input

    输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的总数,然后是n行数据,每行包括两个数据Ti_s,Ti_e (1<=i<=n),分别表示第i个节目的开始和结束时间,为了简化问题,每个时间都用一个正整数表示。n=0表示输入结束,不做处理。 
  Output

    对于每个测试实例,输出能完整看到的电视节目的个数,每个测试实例的输出占一行。

思路  贪心。*根据节目的结束时间排序再进行贪心

AC代码:

#include <cstdio>
#include <algorithm> 

using namespace std;

struct time{
    int s;
    int e;
}t[100];
bool cmp(time a,time b){
    if(a.e==b.e)
        return a.s<b.s;
    return a.e<b.e;
}

int main(){
    int n,i,j;
    int num;
//    scanf("%d",&n);
    while(scanf("%d",&n)!=EOF&&n!=0){                   //没注意审题...多组... 
        for(i=0;i<n;i++)
            scanf("%d %d",&t[i].s,&t[i].e);
        sort(t,t+n,cmp);
/*        i=0;
        while(i<n){
//            if(t[i].e<=t[i+1].s)        若以开始时间排序要考虑的可能情况较多 
//                ++num;                  以结束时间排序只用判断时间是否重叠b 
//                ++i;
//            else{
                x=0;
                for(j=1;;j++){
                    if(t[i].e<=t[i+j].s)
                        break;
                    else if(t[i].e>=t[i+j].e)++x;
                }
                if(x>=1)num=num+x;
                else if(x==0)++num;
                i=i+j;
                
//            }
        }    */
        j=0;
        num=1;
        for(i=1;i<n;i++){
            if(t[j].e<=t[i].s){
                ++num;
                j=i;
            }
        }
        printf("%d\n",num);       
    }
    return 0;
}

*同样的代码,选C++提交是TLE,选G++提交是AC_(:з」∠)_

 

I_一元三次方程求解

  a*x^3+b*x^2+c*x+d=0约定该方程存在三个不同实根(根的范围在-100至100之间),且根与根之差的绝对值>=1。
要求由小到大依次在同一行输出这三个实根(根与根之间留有空格),并精确到小数点后2位。

  Input

    有多组测试数据,对于每组测试数据,仅有一行,包括四个数,a, b, c, d,相邻两个数由空格隔开。

  Output

    对于每组测试数据,输出三个解,要求从小到大输出,相邻两个数用空格隔开。

思路  由零点定理可知,记方程f(x)=0,若存在2个数x1和x2(x1<x2),f(x1)*f(x2)<0,则在(x1,x2)之间一定有一个根。故采用枚举法求该题的解。

AC代码:

#include <stdio.h>
//using namespace std;
const double dx=0.005;
const double MAX=100;
const double MIN=-100;
      
double a,b,c,d;      
double f(double y){
    return a*y*y*y+b*y*y+c*y+d;
}
int main(){
    double x;
    double x1,x2;
    int t;
    while(scanf("%lf %lf %lf %lf",&a,&b,&c,&d)!=EOF){
        x1=MIN-dx;
        x2=MIN+dx;
        t=0;
        for(x=MIN;x<=MAX;x=x+0.01){
            if(t==3)break;
            if(f(x1)*f(x2)<0){
                if(t<2)printf("%.2lf ",x);
                else printf("%.2lf\n",x);
                ++t;
            }
            x1=x1+0.01;x2=x2+0.01;
        }
    }
    return 0;
}

(今天就到这吧,头发要紧(╥╯^╰╥)万万不能秃了

 

D_Boring count

  You are given a string S consisting of lowercase letters, and your task is counting the number of substring that the number of each lowercase letter in the substring is no more than K.

  Input

    In the first line there is an integer T , indicates the number of test cases.

    For each case, the first line contains a string which only consist of lowercase letters. The second line contains an integer K. 

    [Technical Specification] 
      1<=T<= 100 
      1 <= the length of S <= 100000 
      1 <= K <= 100000

  Output

    For each case, output a line contains the answer.

思路  用数组记录,对于第i个字符,判断该字符在[0,i]的出现次数是否大于k。如果出现次数小于k则计算[0,i]区间内以i为结尾的符合条件的子序列

  *以第i个字符为结尾的符合条件的最长串长度 = 以第i个字符为结尾的符合条件的字串的个数

 (至今未理解上面这句话....orz....

转载于:https://www.cnblogs.com/anonym/p/8269465.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值