当前位置: 首页 > news >正文

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

官方题解: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]);
    }
}
预处理+二分

 

转载于:https://www.cnblogs.com/Roni-i/p/8022466.html

相关文章:

  • 使用bind元素创建变量
  • Day1 Java编程环境和变量
  • Python中求1到20平方的两种方法
  • Go语言之讲解GOROOT、GOPATH、GOBIN
  • 评论列表显示及排序,个人中心显示
  • jQuery效果之jQuery Color animation 色彩动画扩展
  • Qt---自定义界面之QStyle
  • 再学习之Spring(面向切面编程).
  • java:解决eclipse配置Tomcat时找不到server选项
  • Qt532.QSettings_默认分隔符
  • python 高阶函数三 filter()和sorted()
  • bzoj1036[ZJOI2008]树的统计Count 树链剖分+线段树
  • 自然语言处理入门学习(一)
  • 文件和目录权限chmod 更改所有者和所属组chown umask 隐藏权限lsattr/chattr
  • 面向对象java知识汇总题
  • Android组件 - 收藏集 - 掘金
  • angular2 简述
  • C++入门教程(10):for 语句
  • CSS3 变换
  • Cumulo 的 ClojureScript 模块已经成型
  • Vue UI框架库开发介绍
  • Vue官网教程学习过程中值得记录的一些事情
  • 初识MongoDB分片
  • 从PHP迁移至Golang - 基础篇
  • 工作中总结前端开发流程--vue项目
  • 离散点最小(凸)包围边界查找
  • 前嗅ForeSpider采集配置界面介绍
  • 什么是Javascript函数节流?
  • 算法-图和图算法
  • 小程序01:wepy框架整合iview webapp UI
  • 小程序开发中的那些坑
  • 400多位云计算专家和开发者,加入了同一个组织 ...
  • 如何用纯 CSS 创作一个货车 loader
  • # 再次尝试 连接失败_无线WiFi无法连接到网络怎么办【解决方法】
  • #我与Java虚拟机的故事#连载01:人在JVM,身不由己
  • ( 10 )MySQL中的外键
  • (22)C#传智:复习,多态虚方法抽象类接口,静态类,String与StringBuilder,集合泛型List与Dictionary,文件类,结构与类的区别
  • (42)STM32——LCD显示屏实验笔记
  • (70min)字节暑假实习二面(已挂)
  • (Redis使用系列) Springboot 使用Redis+Session实现Session共享 ,简单的单点登录 五
  • (备忘)Java Map 遍历
  • (读书笔记)Javascript高级程序设计---ECMAScript基础
  • (牛客腾讯思维编程题)编码编码分组打印下标题目分析
  • (转)C语言家族扩展收藏 (转)C语言家族扩展
  • (转)母版页和相对路径
  • (转载)Linux 多线程条件变量同步
  • .cfg\.dat\.mak(持续补充)
  • .naturalWidth 和naturalHeight属性,
  • .NET / MSBuild 扩展编译时什么时候用 BeforeTargets / AfterTargets 什么时候用 DependsOnTargets?
  • .Net IE10 _doPostBack 未定义
  • .NETCORE 开发登录接口MFA谷歌多因子身份验证
  • /etc/shadow字段详解
  • /var/log/cvslog 太大
  • @RequestParam详解
  • @德人合科技——天锐绿盾 | 图纸加密软件有哪些功能呢?