练习赛1

A.题目链接

签到题
Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#define INF 0x3f3f3f3f
#define LL long long 
using namespace std;
const int AX = 1e4+666;
double a[AX];
int main(){
    int n ;
    while( scanf("%d",&n) && n ){
        double sum = 0.0;
        for( int i = 0 ; i < n ; i++ ){
            scanf("%lf",&a[i]);
            sum += a[i];
        }
        double ave = sum / (double)n ;
        sort( a , a + n );
        int pos = upper_bound( a, a+n , ave ) - a;
        printf("%d\n",pos);
    }
    return 0 ;  
}

B.题目链接

题意:给一个矩形,两个操作,折来折去的,最后询问以新得到的图形左下角为原点,给出几个询问的坐标,戳一个孔,要求你求出会得到几个孔。。。
思路:模拟即可,最后输出的时候注意坐标不同的转换。
Code:

#include <bits/stdc++.h>
using namespace std;
const int AX = 1e3+66;
int vis[AX][AX];
int res[AX][AX];
int main(){
    int n , m , t,  p;
    while ( scanf("%d%d%d%d",&n,&m,&t,&p) && n && m && t && p ){
        memset( vis , 0 , sizeof(vis) );
        for( int i = 0 ; i < m ; i++ ){
            for( int j = 0 ; j < n ; j++ ){
                vis[i][j] = 1;
            }
        }
        int left = 0 ;
        int down = 0 ;
        int x , y ;  
        int op;
        for( int i = 0 ;  i < t ;i ++ ){
            //cout << "?? : " << vis[3][4] << endl;
            scanf("%d%d",&op,&x);
            if( op == 2 ){
                down += x  ;
                int s = 0 ;
                m = max( m , down + x );
                for( int k = down ; k < down + x ; k++ ){
                    s ++;
                    for( int j = left ; j < n ; j++ ){
                        vis[k][j] += vis[down-s][j];
                    }
                }
            }else{
                left += x  ;
                int s = 0;
                n = max( n , left + x );
                for( int j = left ; j < left + x ; j++ ){
                    s ++;
                    for( int k = down ; k < m ; k++ ){
                        vis[k][j] += vis[k][left-s];
                    }
                }
            }
        }

        for( int i = 0 ; i < p ; i++ ){
            scanf("%d%d",&x,&y);    

            printf("%d\n",vis[y+down][x+left]);
        }
    }
    return 0 ;
}

C.题目链接

题意:将一个正整数x分解成几个连续的数相加,输出数最多的那一组。
思路:等差数列求和: (a1+a1+(n-1)) * n / 2 = x
可得:2*x / n + 1 - n = 2 * a1
又因为首项大于等于1,所以 a1 = 2*x/n-n+1 >= 1
可得:2*x >= n*n = > n <= sqrt(2*x)
然后数据范围内1s暴力足够啦。

Code:

#include <bits/stdc++.h>
using namespace std;
int main(){
    int x ;
    while( scanf("%d",&x) && x ){
        int lim = sqrt(2)*sqrt(x) + 1 ;
        for( int n = lim ; n >= 1 ; n-- ){
            if( 2 * x % n == 0 ){
                int temp = 2 * x / n - n + 1;
                if( temp && temp % 2 == 0 ){
                    printf("%d %d\n",temp / 2 , n );
                    break;  
                }
            }
        }
    }
    return 0 ;
}

I.题目链接
题意:给n个菜谱,总共有m个材料,要求求出最多能做几个菜谱能够让材料都用偶数个。
思路:
Code:

J.题目链接
题意:求一个矩形区域(矩形!!!,做的时候以为只要围起来就行了,bfs一直错)
周围的方块都要高于区域内的任何一块。
思路:暴力即可。
Code;

#include <iostream>
#include <cstdio>
#define INF 0x3f3f3f3f
using namespace std;
const int AX = 20+6;
int a[AX][AX];
int d , w ; 
int res ; 
int main(){
    while( scanf("%d%d",&d,&w) && d && w ){
        for( int i = 0 ; i < d; i++ ){
            for( int j = 0 ; j < w ; j++ ){
                scanf("%d",&a[i][j]);
            }
        }
        res = 0 ;
        for( int sx = 0 ; sx < d ; sx++ ){
            for( int sy = 0 ; sy < w ; sy++ ){
                for( int ex = sx + 2 ; ex < d ; ex ++ ){
                    for( int ey = sy + 2 ; ey < w ; ey ++ ){
                        int minus = INF;
                        int ans = 0 ;
                        for( int i = sx ; i <= ex ; i++ ) minus = min( minus , a[i][sy] );
                        for( int i = sx ; i <= ex ; i++ ) minus = min( minus , a[i][ey] );
                        for( int i = sy ; i <= ey ; i++ ) minus = min( minus , a[sx][i] );
                        for( int i = sy ; i <= ey ; i++ ) minus = min( minus , a[ex][i] );
                        int f = 1;
                        for( int i = sx + 1 ; i < ex ; ++i ){
                            for( int j = sy + 1; j < ey ; j++ ){
                                if( a[i][j] >= minus ){
                                    ans = 0;
                                    f = 0 ;
                                    break;
                                }else ans += minus - a[i][j];
                            }
                            if( !f ) break;
                        }
                        res = max( res , ans ) ;
                    }
                }
            }
        }
        printf("%d\n",res);
    }
    return 0 ;
}

K.题目链接
题意:给定的2个字符串,如果完全相同输出一个字符串,只有一个引号的内容不一样,输出另一个,其他情况输出又一个。。。
思路:模拟模拟。。。
Code:

#include <bits/stdc++.h>
using namespace std;
const int AX = 1e3+66;
char a[AX];
char b[AX];
int sa[AX];
int sb[AX];
int main(){
    while( scanf("%s",a) ){
        if( a[0] == '.' ) break;
        scanf("%s",b);
        int cnta = 0 ;
        int cntb = 0 ;
        if( !strcmp(a,b) ){
            printf("IDENTICAL\n");
        }else{
            int lena = strlen(a);
            int lenb = strlen(b);
            for( int i = 0 ; i < lena ; i++ ){
                if( a[i] == '"' ){
                    sa[cnta++] = i;
                }
            }
            for( int i = 0 ; i < lenb ; i++ ){
                if( b[i] == '"' ){
                    sb[cntb++] = i;
                }
            }
            if( cnta != cntb ){
                printf("DIFFERENT\n");
                continue;
            }   
            int ans = 0 ;
            for( int i = 0 ; i < cnta - 1 ; i+=2 ){
                int j = sa[i] + 1 ; 
                int k = sb[i] + 1 ;

                while( j < sa[i+1] && k < sb[i+1] ){
                    if( a[j] != b[k] ){
                        break;
                    }
                    k++;
                    j++ ;
                }
                if( k != sb[i+1] || j != sa[i+1] ) ans ++ ;
            }
            if( ans >= 2 ){
                printf("DIFFERENT\n");
                continue;
            }

            int ta = -1 ;
            int tb = -1 ;
            int f = 1 ;
            for( int i = 0 , j = 0  ; i < lena && j < lenb ; ){
                if( a[i] == '"' )  { i = sa[ta+2] + 1; ta += 2 ;}
                else i ++ ;
                if( b[j] == '"' )  { j = sb[tb+2] + 1; tb += 2 ;}
                else j ++;
                if( a[i] != b[j] ){
                    f = 0;
                    break;
                }
            }
            if( f ) printf("CLOSE\n");
            else printf("DIFFERENT\n");
        }
    }
    return 0 ;  
}

L.t题目链接
题意:给一个容量,一个数组,求出最接近容量的一对。
思路:暴力。。还是暴力。。。
暴力求出任意2个数的和,然后二分即可。
Code:

#include <iostream>
#include <algorithm>
#include <stdio.h>
#define INF 0x3f3f3f3f
#define LL long long 
using namespace std;
const int AX = 2e6+666;
LL a[AX];
LL b[AX];
int main(){
    int n ;
    LL m ;
    while( scanf("%d%lld",&n,&m) && n && m ){
        for( int i = 0 ; i < n ; i++ ){
            scanf("%lld",&a[i]);
        }
        sort( a , a + n );
        if( a[0] + a[1] > m ){
            printf("NONE\n");
            continue;
        }else{
            int tot = 0 ;
            for( int i = 0 ; i < n ; i++ ){
                for( int j = 0 ; j < n ; j++ ){
                    if( i == j ) continue;
                    b[tot++] = a[i] + a[j];
                }
            }
            sort( b ,b + tot );
            if( b[tot-1] <= m ){
                printf("%lld\n",b[tot-1]);
                continue;
            }
            int pos = lower_bound( b , b + tot , m ) - b;
            if( b[pos] > m ) pos --;
            printf("%lld\n",b[pos]);
        }
    }
    return 0 ;  
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值