[HG]奋斗赛G
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的更多相关文章
- HG奋斗赛B[20190429]
T1 >传送门< 记忆化搜索,听说有更简单的方法(但博主比较菜) #include <cstdio> #include <cstdlib> #define ll l ...
- HG奋斗赛A[20190428]
T1 很简单,判断这个字符串有多少个不同的字符,让后用k减一减 注意: 1.如果不同字符数大于k,不要输出负数 2.变量名别打错 上代码 #include <cstdio> #includ ...
- [HG]奋斗赛M
题A 请进入链接↑ 题B 请进入链接↑ 题C 请进入链接↑ 题D 请进入链接↑ 题E 请进入链接↑ 题F 懒得写了,借用一下Chtholly_Tree巨 ...
- 2016湖南省赛----G - Parenthesis (括号匹配)
2016湖南省赛----G - Parenthesis (括号匹配) Bobo has a balanced parenthesis sequence P=p 1 p 2…p n of lengt ...
- 2016年省赛 G Triple Nim
2016年省赛 G Triple Nimnim游戏,要求开始局面为先手必败,也就是异或和为0.如果n为奇数,二进制下最后一位只有两种可能1,1,1和1,0,0,显然异或和为1,所以方案数为0如果n为偶 ...
- 2020安徽程序设计省赛 G序列游戏
2020安徽程序设计省赛 G序列游戏 有一个序列w,初始为空.再给出一个长度为m 单调递增的序列a.你需要对序列w 作如下n 次操作: (1)操作0,在序列尾部添加数字0. (2)操作1,在序列尾部添 ...
- 第八届河南省赛G.Interference Signal(dp)
G.Interference Signal Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 17 [Submit][Status ...
- 第七届河南省赛G.Code the Tree(拓扑排序+模拟)
G.Code the Tree Time Limit: 2 Sec Memory Limit: 128 MB Submit: 35 Solved: 18 [Submit][Status][Web ...
- 2016年省赛G题, Parenthesis
Problem G: Parenthesis Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 398 Solved: 75[Submit][Status ...
随机推荐
- Centos7最小安装化后安装图形界面
首先需要对系统进行更新 yum -y upgrade 然后安装桌面组件包 ,在命令行下输入下面的命令来安装 Gnome 包 yum groupinstall "GNOME Desktop&q ...
- pthon之mock应用
研发过程中常见分工合作开发接口,但互相之间接口有依赖,这时候便可以使用mock 目录 1.安装 2.使用mock调试自己写的方法 3.使用mock解除依赖关系 1.安装 由于我的是python2.7, ...
- 【HANA系列】SAP HANA DB 和SAP HANA studio version查看
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[HANA系列]SAP HANA DB 和SAP ...
- 不起眼的vim.转自https://blog.csdn.net/iplayvs2008/article/details/51508599
如果我的关于这个话题的最新帖子没有提醒到你的话,那我明确地说,我是一个 Vim 的粉丝.所以在你们中的某些人向我扔石头之前,我先向你们展示一系列“鲜为人知的 Vim 命令”.我的意思是,一些你可能以前 ...
- jdbc步骤:
一.注册数据库驱动 Class.forName("com.mysql.jdbc.Driver"); 二.建立连接(Connection) Connection conn = Dri ...
- Oracle的substr函数简单用法(转)
转:http://www.cnblogs.com/nicholas_f/articles/1526063.html substr(字符串,截取开始位置,截取长度) //返回截取的字 substr('H ...
- Java中获取大小:length、length()、size()
1. java 中的 length 属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了 length 这个属性. 2. java 中的 length() 方法是针对字符串说的,如 ...
- 如何在Web工程中实现任务计划调度
转载自: http://www.oschina.net/question/146385_37793?sort=time 下面就Servlet侦听器结合Java定时器来讲述整个实现过程.要运用Servl ...
- [BZOJ 3731] Gty的超级妹子树 (树分块)
[BZOJ 3731] Gty的超级妹子树 (树分块) 题面 给出一棵树(或森林),每个点都有一个值.现在有四种操作 1.查询x子树里>y的值有多少个 2.把点x的值改成y 3.添加一个新节点, ...
- SpringMVC Controller单例和多例(转)
首先上测试代码 import org.springframework.context.annotation.Scope; import org.springframework.stereotype.C ...