【noip模拟赛 sword,zero,2048】 题解
1、光剑
(sword.pas/c/cpp)
【题目描述】
小林和亮亮各有一把光剑,长度分别为 a 和 b,他们拿光剑进行比试。每一回合,长光剑会砍向短光剑,砍完后,短光剑完好无损,而长光剑则被截成两段,被截去的长度恰好等于短光剑的长度。若两把光剑长度相等,则比试结束。请问小林和亮亮将比试多少回合?
【输入格式】
第一行一个整数 T,表示数据组数。
接下来 T 行每行两个正整数 a,b,表示初始状态光剑的长度。
【输出格式】
每组数据输出一个整数,表示能进行几个回合的比试。
【样例输入】
3
1 8
3 7
6 6
【样例输出】
7
4
0
【数据规模】
对于 40%的数据,0 < a,b <= 1000, 1 <= T <= 20;
对于 100%的数据,0 < a,b <= 10^18,1 <= T <= 1000。
题解:模拟辗转相除。
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
ll x, y, T;
int main()
{
freopen("sword.in","r",stdin);
freopen("sword.out","w",stdout);
ios::sync_with_stdio(false);
cin>>T;
for(ll a = 1; a <= T; a++)
{
ll round = 0, now;
cin>>x>>y;
if(x < y) swap(x, y); // x 大 y 小
if(x == y)
{
cout<<0<<endl;
continue;
}
while(x % y != 0)
{
round += x/y; // x = 7 y = 3
now = x % y; // now = 1
x = y;
y = now;
}
cout<<round-1+x/y<<endl;
}
}
2、化零
(zero.pas/c/cpp)
Describe
有5个集合,每个集合N个元素,从每个集合选出一个数,共5个,问是否可以使和为0。
IN put:
第一行一个整数 N,表示集合的大小。
接下来五行每行 N个整数,表示这五个集合内的元素。
OUT put:
如果能找到符合条件的五个数,则输出“YES”,否则输出“NO”。
example:
in
3
1 -2 9
-1 2 1
-3 5 1
-1 7 6
-4 -1 -7
out
YES
数据范围:
N<=20 30%
N<=200 100%
题解:
考虑 N <= 20 直接N^5暴力
对于 N > 20 考虑一种赌博式的想法
如果有合法解的话,不妨设在前两个集合和后三个集合存在相反数
这样我们可以预先处理出N^2 和 N^3 的方案数,再进行组合,看是否有相反数
这时候我们先排序再套个lower_bound就ok了
最差在没有解大概跑了1.11s
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 210;
ll a[maxn], b[maxn], c[maxn], d[maxn], e[maxn], n;
ll ans1[41000], ans2[8000100], cnt1 = 0, cnt2 = 0;
inline ll read()
{
ll k=0,f=1;
char c=getchar();
while(!isdigit(c))
{
if(c=='-')f=-1;
c=getchar();
}
while(isdigit(c))
{
k=(k<<1)+(k<<3)+c-48;
c=getchar();
}
return k*f;
}
int main()
{
n = read();
for(int i = 1; i <= n; i++) a[i] = read();
for(int i = 1; i <= n; i++) b[i] = read();
for(int i = 1; i <= n; i++) c[i] = read();
for(int i = 1; i <= n; i++) d[i] = read();
for(int i = 1; i <= n; i++) e[i] = read();
if(n <= 25)
{
for(int v = 1; v <= n; v++)
for(int w = 1; w <= n; w++)
for(int x = n; x >= 1; x--)
for(int y = n; y >= 1; y--)
for(int z = n; z >= 1; z--)
{
if(a[v] + b[w] + c[x] + d[y] + e[z] == 0)
{
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
return 0;
}
else
{
for(int v = 1; v <= n; v++)
for(int w = 1; w <= n; w++)
ans1[++cnt1] = a[v]+b[w];
for(int x = 1; x <= n; x++)
for(int y = 1; y <= n; y++)
for(int z = 1; z <= n; z++)
ans2[++cnt2] = -1*(c[x]+d[y]+e[z]);
sort(ans1+1, ans1+1+cnt1);
for(int i = 1; i <= cnt2; i++)
{
int now = lower_bound(ans1+1, ans1+1+cnt1, ans2[i])-ans1;
if(ans1[now] == ans2[i])
{
cout<<"YES"<<endl;
return 0;
}
}
cout<<"NO"<<endl;
return 0;
}
}
3、2048
(2048.pas/c/cpp)
【题目描述】
小林和亮亮最近正在重温 2048 这款游戏。由于他们的游戏水平高超,觉得没有什么挑战性,于是决定自己设计一款类似的游戏。他们设计的游戏中,数字排成了一个线性的序列,每次玩家可以将序列中任意两个相同的数 a 合并,成为一个新的数 2*a,当合并出 2048 时游戏即获得胜利。设计完后,他们发现这个游戏比原来的版本更加简单了,于是他们就开始计算,对于一个给定的长度为 n 的序列,它共有多少子序列可以合并出 2048。请给出这个数模 998244353 后的值。
【输入格式】
第一行有一个整数 n。
第二行 n个整数Ai,表示数列中的数。
【输出格式】
一个整数,即为所求的答案。
【样例输入】
2
2048 2048
【样例输出】
3
【数据规模】
对于 40%的数据,n <= 20;
对于 70%的数据,n <= 500;
对于100%的数据,1 <= n <= 100000,1 <= Ai <= 2048。
题解:
组成2048必须是2的幂次方。
不是的统计到cnt,可以直接扔掉了。
设dp[i][j]表示使用前i个数使他们和为j的方案数
ans = dp[n-cnt][2048]*(1<<cnt)
code不是我的= =考试没写出来,现在也没写出来qwq
#include <cstdio>
#include <cstring>
#define MOD 998244353LL
#define F 2100
using namespace std;
typedef long long LL;
int n, x, cnt = 0;
LL a[F], num[F];
void Read(int &x)
{
x = 0;
char ch = getchar();
while (ch < '0' || ch > '9') ch = getchar();
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - '0';
ch = getchar();
}
}
int main()
{
freopen("2048.in", "r", stdin);
freopen("2048.out", "w", stdout);
Read(n);
memset(num, 0, sizeof(num));
memset(a, 0, sizeof(a));
for (int i = 0; i <= 11; i++)
num[1<<i] = i;
for (int i = 1; i <= n; i++)
{
Read(x);
if (!num[x] && x != 1) { cnt++; continue; }
for (int j = 2048; j >= 1; j--)
if (a[j])
{
if (j + x <= 2048) a[j+x] = (a[j+x] + a[j]) % MOD;
else a[2048] = (a[2048] + a[j]) % MOD;
}
a[x]++;
}
for (int i = 1; i <= cnt; i++)
a[2048] = a[2048] * 2LL % MOD;
printf("%d\n", a[2048]);
return 0;
}
【noip模拟赛 sword,zero,2048】 题解的更多相关文章
- NOIP模拟赛 打铁的匠 题解
[问题描述] Mark Douglas是一名优秀的锻造师.与他优秀的锻造水平不相符,他非常穷,以至于很多好刀都因为缺少素材缺少资金无法打造. Mark把他有能力锻造的所有n种刀建成了一棵锻造树,除了第 ...
- CH Round #58 - OrzCC杯noip模拟赛day2
A:颜色问题 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2358%20-%20OrzCC杯noip模拟赛day2/颜色问题 题解:算一下每个仆人到它的目的地 ...
- CH Round #49 - Streaming #4 (NOIP模拟赛Day2)
A.二叉树的的根 题目:http://www.contesthunter.org/contest/CH%20Round%20%2349%20-%20Streaming%20%234%20(NOIP 模 ...
- CH Round #48 - Streaming #3 (NOIP模拟赛Day1)
A.数三角形 题目:http://www.contesthunter.org/contest/CH%20Round%20%2348%20-%20Streaming%20%233%20(NOIP模拟赛D ...
- CH Round #54 - Streaming #5 (NOIP模拟赛Day1)
A.珠 题目:http://ch.ezoj.tk/contest/CH%20Round%20%2354%20-%20Streaming%20%235%20(NOIP模拟赛Day1)/珠 题解:sb题, ...
- contesthunter暑假NOIP模拟赛第一场题解
contesthunter暑假NOIP模拟赛#1题解: 第一题:杯具大派送 水题.枚举A,B的公约数即可. #include <algorithm> #include <cmath& ...
- 大家AK杯 灰天飞雁NOIP模拟赛题解/数据/标程
数据 http://files.cnblogs.com/htfy/data.zip 简要题解 桌球碰撞 纯模拟,注意一开始就在袋口和v=0的情况.v和坐标可以是小数.为保险起见最好用extended/ ...
- 队爷的讲学计划 CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的讲学计划 题解:刚开始理解题意理解了好半天,然后发 ...
- 队爷的Au Plan CH Round #59 - OrzCC杯NOIP模拟赛day1
题目:http://ch.ezoj.tk/contest/CH%20Round%20%2359%20-%20OrzCC杯NOIP模拟赛day1/队爷的Au%20Plan 题解:看了题之后觉得肯定是DP ...
随机推荐
- springMVC基于注解的控制器
springMVC基于注解的控制器 springMVC基于注解的控制器的优点有两个: 1.控制器可以处理多个动作,这就允许将相关操作写在一个类中. 2.控制器的请求映射不需要存储在配置文件中.使用re ...
- 关于echart 图表自适应问题的解决办法
<div id="divEnergy" style="width: 100%; height: 300px; border: 5px solid red; &quo ...
- 数据结构与算法C语言所有头文件汇总 —— 持续更新
header.h // 顺序表的结构定义 #define Maxsize 100 //const int Maxsize = 100; // 预先定义一个足够大的常数 typedef struct { ...
- VC编程操作word2010生成表格
作者:朱金灿 来源:http://blog.csdn.net/clever101 一. 右键单击工程节点,然后选择添加类,如下图: 二. 添加TypeLib中的MFC类,如下图: 三. 选 ...
- 21_ConcurrentHashMap和ConcurrentSkipListMap
[简述] ConcurrentHashMap内部使用段(Segment)来表示这些不用的部分,每个段其实就是一个小的HashTable,他们有自己的锁,只要多个修改操作发生在不同的段上,他们就可以并发 ...
- java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.
1.前几天搭建单元测后,今天用其测试,结果报了这个问题.网上搜索后,刚开始以为原因是 Spring的 依赖版本的问题,我现在的依赖是: 因为其他的比如说 spring-content spring ...
- mysql主键问题
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/qq_22314145/article/details/80824660 MySQL主键 一. MyS ...
- 华为手机在开发Android调试时logcat不显示输出信息的解决办法
手机连接电脑RUN AS logcat 提示:Unable to open log device '/dev/log/main': No such file or directory 信息 本人华为C ...
- DevExpress之ChartControl用法
DevExpress中的ChartControl顾名思义就是数据基于图表展示,其关键在于Series上的处理. using System; using System.Drawing; using De ...
- Elasticsearch查询类型
Elasticsearch支持两种类型的查询:基本查询和复合查询. 基本查询,如词条查询用于查询实际数据. 复合查询,如布尔查询,可以合并多个查询, 然而,这不是全部.除了这两种类型的查询,你还可以用 ...