T1

题目描述

安娜斯塔西娅喜欢去乌日扬迪安中央公园散步。 但她对简单的散步不感兴趣,于是她开始收集公园里的鹅卵石。 一开始,她决定收集所有她能在公园里找到的鹅卵石。

她只有两个口袋。 她能在每个口袋里同时放最多k个鹅卵石。第i种鹅卵石有w[i]个。 安娜斯塔西娅很有责任感,所以她从不把不同类型的鹅卵石混在一个口袋里。 然而,她可以把不同种类的鹅卵石放在不同的口袋。 不幸的是,她不能把所有的时间都花在收集鹅卵石上,所以她每天只能从公园里收集一次鹅卵石。

考虑到安娜斯塔西娅不能把不同类型的鹅卵石放在同一个口袋里,请帮助她找到收集乌日扬甸中央公园所有鹅卵石所需的最短天数。

解法:直接模拟

#include <cstdio>
#define ll long long inline ll read(){
ll x = ; int zf = ; char ch = ' ';
while (ch != '-' && (ch < '' || ch > '')) ch = getchar();
if (ch == '-') zf = -, ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar(); return x * zf;
} int main(){
int n = read(), k = read(), a;
ll tot = ;
for (int i = ; i < n; ++i)
a = read(), tot += (a % k) ? (a / k + ) : (a / k);
tot = (tot & ) ? ((tot >> ) + ) : (tot >> );
printf("%lld", tot);
return ;
}

T2

题意:给你一个等比数列,首项为b1,公比为q,现在Masha在黑板上从首项开始书写这个等比数列,直到数列某项的绝对值大于l,给定m个整数,若该等比数列中的某项等同于这m个整数,则不会被写出。
问Masha会写出多少个数字?如果她会写出无穷多个数字,输出inf
注意: b1,q可能为0

解法:

特判q为0,1,-1;b1为0的情况
然后其他情况直接用set暴力模拟即可
有一个坑点:
----如果abs(b) > l即使q=0,0没有限制也要输出0,蒟蒻不知道为什么

#include <cstdio>
#include <cmath>
#include <set>
#define ll long long using namespace std; inline ll read(){
ll x = ; int zf = ; char ch = ' ';
while (ch != '-' && (ch < '' || ch > '')) ch = getchar();
if (ch == '-') zf = -, ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar(); return x * zf;
} set<ll> st; int main(){
ll b = read(), q = read(), l = read(), m = read();
for (int i = ; i <= m; ++i)
st.insert(read());
if (q == ){
if (st.find() != st.end() || (l < )){
if (st.find(b) != st.end() || (abs(b) > l))
printf("");
else
printf("");
}
else if (abs(b) > l)
printf("");
else
printf("inf");
return ;
}
else if (q == ){
if ((abs(b) > l) || st.find(b) != st.end())
printf("");
else
printf("inf");
return ;
}
else if (q == -){
if (abs(b) > l){
printf("");
return ;
}
if (st.find(b) == st.end()){
printf("inf");
return ;
}
if (st.find(-b) == st.end()){
printf("inf");
return ;
}
printf("");
return ;
}
else if (b == ){
if (st.find() != st.end() || (l < ))
printf("");
else
printf("inf");
return ;
}
else{
int cnt = ;
for (ll i = b; abs(i) <= l; i *= q){
if (st.find(i) == st.end())
++cnt;
}
printf("%d", cnt);
}
return ;
}

T3

题意:

定义一个函数,函数如下(请找个markdown编辑器贴一下):

$f[l,r]=\sum_{i=l}^{r-1}|a_i-a_{i-1}|\times(-1)^{i-l}$

|x|表示x的绝对值。
现在给你一个函数,请取恰当的l,r使f值最大,请输出最大的f值

解法:不说了直接DP

#include <cstdio>
#include <cmath>
#include <algorithm>
#define max(a,b) ((a>b)?a:b)
#define ll long long using namespace std; inline ll read(){
ll x = ; int zf = ; char ch = ' ';
while (ch != '-' && (ch < '' || ch > '')) ch = getchar();
if (ch == '-') zf = -, ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar(); return x * zf;
} int a[];
ll f[][]; int main(){
int n = read();
for (int i = ; i <= n; ++i)
a[i] = read();
for (int i = ; i < n; ++i)
a[i] = abs(a[i] - a[i + ]);
ll ans = a[];
f[][] = a[], f[][] = ;
for (int i = ; i < n; ++i){
if (i & ){
f[i][] = max(f[i - ][] + a[i], a[i]);
f[i][] = f[i - ][] - a[i];
}
else{
f[i][] = max(f[i - ][] + a[i], a[i]);
f[i][] = f[i - ][] - a[i];
}
ans = max(max(f[i][], f[i][]), ans);
}
printf("%lld", ans);
return ;
}

T4

题意:总共有n个节点,m条路径,要求其中m-2条路径走两遍,剩下2条路径仅走一遍,问不同的路径总数有多少,如果仅走一遍的两条边不同则将这两条路径视为不同。

解法:DFS判图的联通性+数学

#include <cstdio>
#define ll long long struct Edge{
int to, next;
} edges[]; int head[], edge_num = ;
int cnt[]; inline ll read(){
ll x = ; int zf = ; char ch = ' ';
while (ch != '-' && (ch < '' || ch > '')) ch = getchar();
if (ch == '-') zf = -, ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar(); return x * zf;
} inline void addEdge(int from, int to){
++cnt[from];
edges[++edge_num] = (Edge){to, head[from]};
head[from] = edge_num;
} bool vis[];
int rd[]; void DFS(int u){
for(int c_e = head[u]; c_e; c_e = edges[c_e].next){
int v = edges[c_e].to;
if(!vis[v]){
vis[v] = ;
DFS(v);
}
}
} inline ll cac(ll num){
return (((num - ) * num) >> );
} int main(){
int n = read(), m = read();
ll zh = ;
for(int i = ; i <= m; i++){
int u = read(), v = read();
++rd[u], ++rd[v];
if(u != v)
addEdge(u, v), addEdge(v, u);
else
++zh;
}
for(int i = ; i <= n; ++i)
if(head[i] != ){
vis[i] = , DFS(i);
break;
}
ll ans = ;
for(int i = ; i <= n; ++i)
if(!vis[i] && rd[i]){
printf("");
return ;
}
for(int i = ; i <= n; ++i)
ans += 1ll * cac(cnt[i]);
ans += zh * (m - ) - cac(zh);
printf("%lld", ans);
return ;
}

T5

题意:有k种可乐,第i瓶可乐的CO2浓度是ai/1000,问要配置出浓度n/1000的可乐,最少需要几瓶可乐。

解法:题目very interestring但其实就是个广搜

#include <cstdio>
#include <algorithm>
#include <queue>
#define ll long long using namespace std; int a[];
int ans[];
bool vis[]; inline ll read(){
ll x = ; int zf = ; char ch = ' ';
while (ch != '-' && (ch < '' || ch > '')) ch = getchar();
if (ch == '-') zf = -, ch = getchar();
while (ch >= '' && ch <= '') x = x * + ch - '', ch = getchar(); return x * zf;
} queue<int> que; int main(){
int n = read(), k = read();
for(int i = ; i < k; ++i)
a[i] = read() - n;
sort(a, a + k);
k = unique(a, a + k) - a;
if(a[] * a[k - ] > ){
printf("-1\n");
return ;
}
for(int i = ; i < k; ++i){
que.push(a[i]);
ans[a[i] + ] = , vis[a[i] + ] = ;
}
int u;
while(!que.empty() && !vis[]){
u = que.front(), que.pop();
for(int i = ; i < k; ++i){
if((u + a[i]) <= && (u + a[i]) >= - && !vis[u + a[i] + ]){
que.push(u + a[i]);
vis[u + a[i] + ] = ;
ans[u + a[i] + ] = ans[u + ] + ;
}
}
}
printf("%d", ans[]);
return ;
}

[HG]奋斗赛G的更多相关文章

  1. HG奋斗赛B[20190429]

    T1 >传送门< 记忆化搜索,听说有更简单的方法(但博主比较菜) #include <cstdio> #include <cstdlib> #define ll l ...

  2. HG奋斗赛A[20190428]

    T1 很简单,判断这个字符串有多少个不同的字符,让后用k减一减 注意: 1.如果不同字符数大于k,不要输出负数 2.变量名别打错 上代码 #include <cstdio> #includ ...

  3. [HG]奋斗赛M

    题A     请进入链接↑ 题B     请进入链接↑ 题C     请进入链接↑ 题D     请进入链接↑ 题E     请进入链接↑ 题F     懒得写了,借用一下Chtholly_Tree巨 ...

  4. 2016湖南省赛----G - Parenthesis (括号匹配)

    2016湖南省赛----G - Parenthesis (括号匹配)   Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...

  5. 2016年省赛 G Triple Nim

    2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...

  6. 2020安徽程序设计省赛 G序列游戏

    2020安徽程序设计省赛 G序列游戏 有一个序列w,初始为空.再给出一个长度为m 单调递增的序列a.你需要对序列w 作如下n 次操作: (1)操作0,在序列尾部添加数字0. (2)操作1,在序列尾部添 ...

  7. 第八届河南省赛G.Interference Signal(dp)

    G.Interference Signal Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 17 [Submit][Status ...

  8. 第七届河南省赛G.Code the Tree(拓扑排序+模拟)

    G.Code the Tree Time Limit: 2 Sec  Memory Limit: 128 MB Submit: 35  Solved: 18 [Submit][Status][Web ...

  9. 2016年省赛G题, Parenthesis

    Problem G: Parenthesis Time Limit: 5 Sec  Memory Limit: 128 MBSubmit: 398  Solved: 75[Submit][Status ...

随机推荐

  1. VMware 虚拟化编程(2) — 虚拟磁盘文件类型详解

    目录 目录 前文列表 虚拟磁盘文件 VMDK 用户可以创建的虚拟磁盘类型 VixDiskLib 中支持的虚拟磁盘类型 虚拟机文件类型 前文列表 VMware 虚拟化编程(1) - VMDK/VDDK/ ...

  2. C# datatable 导出到Excel

    datatable导出到Excel /// <summary> /// 将DataTable导出为Excel文件(.xls) /// </summary> /// <pa ...

  3. Android安全测试(一)数字签名检测

    1.测试环境 SDK: Java JDK, Android SDK. 下图为利用中间人攻击的手段,将智能电视上所有影片的封面图替换的实际效果图 利用中间人攻击还可以进行token获取等,所以不要轻易使 ...

  4. LeetCode——707 设计链表

    题目: 总而言之就是要用C++手撸链表,我的代码: class MyLinkedList { public: /** Initialize your data structure here. */ M ...

  5. Tensorflow实战 手写数字识别(Tensorboard可视化)

    一.前言 为了更好的理解Neural Network,本文使用Tensorflow实现一个最简单的神经网络,然后使用MNIST数据集进行测试.同时使用Tensorboard对训练过程进行可视化,算是打 ...

  6. JQ判断div是否隐藏

    1. $("#tanchuBg").css("display")   2. $("#tanchuBg").is(":visible ...

  7. 子页面中ifram高度自使用

    HTML: <iframe id="mainframe" name="mainframe" style="width: 100%; border ...

  8. Reverse Linked List(反转单向链表)

    来源:https://leetcode.com/problems/reverse-linked-list Reverse a singly linked list. 递归方法:递归调用直到最后一个节点 ...

  9. git ssh key配置&解决git每次输入密码

    git ssh key配置&解决git每次输入密码:https://blog.csdn.net/qq_42817227/article/details/81415404

  10. $.ajax()方法详解(网上引用)

    jquery中的ajax方法参数总是记不住,这里记录一下. 1.url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址. 2.type: 要求为String类型的参数,请求方式(p ...