浙江中医药大学第十一届程序设计竞赛题解

官方题解:http://www.jnxxhzz.com/Article/article/9.html

2019: 特产

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 548  Solved: 154
[Submit][Status][Web Board]

Description

 

Input


 

Output

 输出一个整数表示dd带回来的特产重量

 

Sample Input

2 3 6 1 3

Sample Output

3 2 
 
【分析】:注意是实数,不要用cin会超时。
【代码】:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define PI 3.14159
int t;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        double n,m;
        scanf("%lf%lf",&n,&m);
        printf("%.0f\n",(m-n));
    }
    return 0;
}
View Code

 


2020: Pizza

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 591  Solved: 141
[Submit][Status][Web Board]

Description

 

Input

 

Output

输出cc最少会获得的卡路里
 

 

Sample Input

1 1 2

Sample Output

2

HINT

 【分析】:最少那就只吃一块pizza。
【代码】:
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define PI 3.14159
int t;
int n;
double k;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%lf",&n,&k);

        printf("%.0f\n",1.0*k);
    }
    return 0;
}
View Code

 

不忘初心,砥砺前行!

2024: cc的神奇背包

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 330  Solved: 115
[Submit][Status][Web Board]

Description

 

Input

 

Output

 

Sample Input

1 4 2 1 2 2 1 3 1 2 3

Sample Output

yes 
【分析】:结构体排序。
【代码】:有注释。
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define PI 3.14159
int t;
int n,k;
struct node
{
    int x,y;
}a[5000];
//int a[5000],b[5000];
int cmp(node a,node b)
{
    return a.x<b.x; //体积小的先放
    return a.y>b.y; //扩容大的先放
}
int f=1;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        f=1;
        scanf("%d%d",&n,&k);
        for(int i=0;i<n;i++)
        {
            scanf("%d%d",&a[i].x,&a[i].y);
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++)
        {
            if(a[i].x>k||k<0)
            {
                f=0;
            }
            else
            {
                k=k-a[i].x+a[i].y;
            }
        }
        if(f) puts("yes");
        else puts("no");
    }
    return 0;
}

/*
n v    //n个礼物 体积为v的背包
ai bi  //每个礼物的体积ai 背包对这件礼物的喜爱程度bi(物体放到背包会扩大的体积)
能不能所有礼物都放到背包
【初始体积k=2】
1 2 k= 2-1+2=3
2 3 k= 3-2+3=4
2 1 k= 4-2+1=3
3 1 k= 3-3+1=1
a升序
b降序
*/
结构体排序

 


2017: 开心的cc

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 147  Solved: 26
[Submit][Status][Web Board]

Description

 

Input

 

Output

 

Sample Input

2 5 1 0 1 1 0 5 1 1 1 1 1

Sample Output

1 5

HINT

 

 
【分析】: 直接看 1比0多的个数 。

【代码】:

#include <bits/stdc++.h>

using namespace std;
int t;
int n,x,cnt;
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        cnt=0;
        scanf("%d",&n);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&x);
            if(x==1) cnt++;
            else cnt--;
        }
        printf("%d\n",max(cnt,0));
    }
    return 0;
}
思维

 


不忘初心,砥砺前行!

2021: 剪纸

Time Limit: 4 Sec  Memory Limit: 128 MB
Submit: 68  Solved: 23
[Submit][Status][Web Board]

Description

 

Input

 

Output

 

Sample Input

1 4

Sample Output

11 
【分析】:蓝桥杯原题改编了一点。

第八届 蓝桥杯 方格分割

【代码】:

#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
using namespace std;
int ans = 0;
int mpt[20+1][20+1];
int N;
int dir[4][2] = {0,1,1,0,0,-1,-1,0};
void dfs(int x,int y)
{
    if(x == 0 || y == 0 || x == N || y == N){
        ans ++;
        return;
    }
    for(int i = 0 ; i < 4 ; i ++)
    {
        int tx = x + dir[i][0];
        int ty = y + dir[i][1];
        if(mpt[tx][ty])continue;
        mpt[tx][ty] = 1;
        mpt[N-tx][N-ty] = 1;
        dfs(tx,ty);
        mpt[tx][ty] = 0;
        mpt[N-tx][N-ty] = 0;
    }
}
int main()
{
    int pp;scanf("%d",&pp);
    while (pp--)
    {
        scanf("%d",&N);
        ans=0;//注意多组数据置位
        memset(mpt,0,sizeof(mpt));
        mpt[N/2][N/2] = 1;
        dfs(N/2,N/2);
        printf("%d\n",ans/4);
    }
   return 0;
}
DFS

 


2014: 一生之敌

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 519  Solved: 59
[Submit][Status][Web Board]

Description

 

Input

 第一行输入一个整数T,表示数据组数。  
每组数据输入一个整数n。

 1 <= T <= 100000 
 0 <= n <= 10^19
保证结果存在 

 

Output

 输出一个整数。

 

Sample Input

3 2 6 100

Sample Output

6 6 114
 
【分析】:这道题实际上就是找2a为为完全平方数的时候, 然后把这些数存起来  (预处理),二分就行了 ,注意用ULL
【代码】:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn = 1400000 + 10;
ULL f[maxn];
void init()
{
    for(int i=0;i<maxn;i++)
    {
         f[i] = 4ull * i * i * i + 2ull * i;
    }
}

int main()
{
    init();
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ULL n;scanf("%llu",&n);
        LL ans = lower_bound(f,f+maxn,n) - f;
        printf("%llu\n",f[ans]);
    }
}
预处理+二分

 

posted @ 2017-12-11 12:19  Roni_i  阅读(386)  评论(0编辑  收藏  举报