HPU16级暑期集训练习(一)

一堆水题也不会写 中间写的想吐mmp 好菜啊

###A 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1994 ####题解

对着上面的公式抄下就好 太长才开始懒得看

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */

int main()
{
    int T;
    scanf("%d",&T);
    while(T--) {
        double y, q;
        double e, f, g;
        scanf("%lf%lf%lf%lf%lf",&y,&q,&e,&f,&g);
        printf("%.1lf\n",y*(1+e/100*q/365)*(1+g/100));
        printf("%.1lf\n",y*(1+f/100*(q+365)/365));
    }
return 0;
}

B 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2052

题解

直接模拟就好了 最讨厌这种图形问题了以前写过记着代码?

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
int main()

{

    int m, n, i;

    while (~scanf("%d%d", &n, &m))

    {
       printf("+");
       for(int i = 0;i < n; i++) printf("-");
       printf("+\n");

        for (int i=0; i<m; i++) {
            printf("|");
            for (int i=0; i<n; i++) {
                printf(" ");
            }   
            printf("|\n");
        }
        printf("+");
       for(int i = 0;i < n; i++) printf("-");
       printf("+\n");

        printf("\n");

    }
    return 0;
}

C 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=3783

题解

记录下ZOJ的个数扔进while里面自己跑if TAT

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */

char str[1110];

int main()
{
    while(gets(str)) {
        if(str[0] == 'E') break;
        int len = strlen(str);
        int a = 0, b = 0, c = 0;
        for(int i = 0;i < len; i++) {
            if(str[i] == 'Z')  a++;
            if(str[i] == 'O')  b++;
            if(str[i] == 'J')  c++;
        }
        while(true) {
            if(a) {
                printf("Z");     a--;
            }
            if(b) {
                printf("O");    b--;
            }
            if(c) {
                printf("J");    c--;
            }
            if(a==0 && b==0 && c==0) break;
        }
        printf("\n");
        memset(str,0,sizeof(str));
    }
return 0;
}

D 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1201

题解

啊啊啊啊嗄 就是这道辣鸡题 wa9 卧槽服自己,该GG了啊啊

讨论两种情况 就是 18岁那年与出生那年的2.28

AC代码
#include <cstdio>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
bool check(int n)
{
    if(n%4==0&&n%100!=0||n%400==0) return true;
    return false;
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--) {
        int ans = 0;
        char ss, rr;
        int y, m, d;
        scanf("%d%c%d%c%d",&y,&ss,&m,&rr,&d);
        if(check(y) && m==2 && d==29) {
            puts("-1"); continue;
        }
        for(int i = 0; i < 18; i++) {
            if(check(y+i)) ans += 366;
            else ans += 365;
        }
        if(check(y+18) && m>2) ans++;
        if(check(y) && m>2 ) ans--;
        printf("%d\n",ans);
    }
return 0;
}码片
###E 题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=2027 ####题解

统计下个数… scanf(“%s”)注意换行问题,,

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */

char str[1110];

int main()
{
    int T;
    scanf("%d",&T);
    getchar();
    while(T--) {

        int a , b, c, d, e;
        a = b = c = d = e = 0;
        memset(str,0,sizeof(str));
        gets(str);
        int len = strlen(str);
        for(int i = 0;i < len; i++) {
            if(str[i] == 'a') {
                a++;
            }
            if(str[i] == 'e') {
                b++;
            }
            if(str[i] == 'i') {
                c++;
            }
            if(str[i] == 'o') {
                d++;
            }
            if(str[i] == 'u') {
                e++;
            }
        }
        printf("a:%d\ne:%d\ni:%d\no:%d\nu:%d\n",a,b,c,d,e);
    //  printf("%d\n",T);
        if(T) printf("\n");
    }
return 0;
}

F 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2674

题解

直接同余定理铁定超时 2009=7*7*41,所以41的阶乘及其以后的数字对2009求模值为零 xjb猜下。。。

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
const int mod = 2009;

int main()
{
    LL n;
    while(~scanf("%lld",&n)) {
        if(n >= mod) puts("0");
        else {
            LL ans = 1;
            for(int i = n; i>1; i--) {
                ans = (ans*(i%mod))%mod;
            }
            printf("%lld\n",ans);
        }

    }
    return 0;
 } 

G 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2031

题解

进制转化的性质.. 代码写的太丑了重新写一遍TAT

####AC代码
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
const int N = 2e4;
int arr[N];

int solve(int m,int n)
{
    int res = 0;
    while(m) {
        arr[res++] = m%n;
        m = m/ n;
    }
    return res;
}
int main()
{
    int n, m;
    while(~scanf("%d%d",&m,&n)) {
        int k;
        k = solve(abs(m),n);
        if(m<0) printf("-");
        for(int i = k-1;i >= 0; i--) {
            if(arr[i]>9)
                printf("%c",arr[i]-10+'A');
            else
                printf("%d",arr[i]);
        }
        printf("\n");
    }
return 0;
}

H 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=2092

题解

计算题 在纸上推推公式?

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */

int main()
{
    int n, m;
    while(~scanf("%d%d",&n,&m)) {
        if(n==0 && m==0) break;
        int res = n*n-4*m;
        int ans = sqrt(res);
        if((n+ans)%2==0 && ans*ans==res) {
            puts("Yes");
        }
        else {
            puts("No");
        }
    }
return 0;
}

I 题目链接http://acm.hpu.edu.cn/problem.php?id=1052

题解

hpuoj的水题 去重函数就搞定了 话说辣鸡oj非要把C放在前面CE一次TAT

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
bool cmp(int a, int b)
{
    return a > b;
}
int arr[110];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i = 0;i < n; i++) {
        scanf("%d",&arr[i]);
    }
    sort(arr,arr+n,cmp);
    int m = unique(arr,arr+n) - arr;
    for(int i = 0;i < m; i++) {
        if(i==0) printf("%d",arr[i]);
        else printf(" %d",arr[i]);
    }
    printf("\n");
return 0;
}

J 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4548

寒假写的 还是不会 要不是记得要打两个表就GG了 只打一个我记得会TLE

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
const int N = 1000000+10;
int a[N], b[N];

void prime()
{
    memset(a,0,sizeof(a));
    int len = 1;
    int m = sqrt(N)+1;
    a[0] = a[1] = 1;
    for(int i = 0;i < m; i++) {
        if(!a[i]) {
            for(int j = i+i; j < N; j += i) {
                a[j] = 1;
            }
        }
    }
}
int shu(int n)
{
    int m = 0;
    while(n) {
        m += n%10;
        n /= 10;
    }
    return m;
}
void biaoprime()
{
    prime();
    memset(b,0,sizeof(b));
    for(int i = 1; i< N; i++) {
        if(!a[i] && !a[shu(i)]) {
            b[i] = b[i-1]+1;
        }
        else 
            b[i] = b[i-1];
    }
}
int main()
{
    int T;
    int k = 0;
    scanf("%d",&T);
    biaoprime();
    while(T--) {
        int w ,z;
        scanf("%d%d",&w,&z);
        printf("Case #%d: %d\n",++k,b[z]-b[w-1]);
    }
return 0;
}

K 题目链接http://codeforces.com/problemset/problem/554/B

题解

cf上的B题 写麻烦了

比较初始状态,每行状态,取最多的就好了;

####AC代码
//重新写下..
#include <bits/stdc++.h>
using namespace std;

string mps[110];
int main()
{
    int n;
    cin>>n;
    for(int i = 0;i < n; i++) cin>>mps[i];
    int res = 0;
    for(int i = 0;i < n; i++) {
        int ans = 0;
        for(int j = 0;j < n; j++) {
            if(mps[i] == mps[j]) ans++;
        }
        res = max(ans,res);
    }
    cout<<res<<endl;
return 0;
}

L 题目链接http://codeforces.com/problemset/problem/632/B

题解

还是cf上的B题 时间那么长没人写我还以为是防AK,,,就没想着企业写,,

前缀和 后缀和问题 先统计B的前缀和 然后对着A的前后扫一遍比大小

####AC代码
#include <bits/stdc++.h>
using namespace std;

#define LL long long
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
#define root 1 , N , 1
#define CLR(a, b) memset(a, (b), sizeof(a))
/* -------------------------------------- */
inline bool scan_d(int &num)
{
        char in;bool IsN=false; in=getchar(); if(in==EOF) return false;
        while(in!='-'&&(in<'0'||in>'9')) in=getchar();
        if(in=='-'){ IsN=true;num=0;} else num=in-'0';
        while(in=getchar(),in>='0'&&in<='9'){ num*=10,num+=in-'0';}
        if(IsN) num=-num;   return true;
}
/*
  #pragma comment(linker, "/STACK:102400000,102400000")
  C++
  ---------------------------------------
    int size = 256 << 20; // 256MB
    char *p = (char*)malloc(size) + size;
    __asm__("movl %0, %%esp\n" :: "r"(p));
    G++
*/
/* -------------------------------------- */
const int N = 1e6;
LL arr[N], brr[N], crr[N];
char str[N];

int main()
{
    LL  n;
    scanf("%lld",&n);
    for(int i = 1;i <= n; i++) {
        scanf("%lld",&arr[i]);
    }
    scanf("%s",str+1);
    for(int i = 1;i <= n; i++) {
        if(str[i] == 'B') 
            brr[i] = brr[i-1]+arr[i];
        else 
            brr[i] = brr[i-1];
    }
    LL x = 0, y = 0;
    for(int i = 1;i <= n; i++) {
        if(str[i] =='A') {
            x += arr[i];
        }
        y = max(y,x+brr[n]-brr[i-1]);
    }
    x = 0;
    for(int i = n; i >= 1; i--) {
        if(str[i] == 'A') {
            x += arr[i];
        }
        y = max(y,x+brr[i-1]);
    }
    printf("%lld\n",max(y,brr[n]));
return 0;
}

不能在修仙了 感觉要瞌睡炸了今天上午TAT

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值