当前位置:网站首页>第 45 届ICPC亚洲区域赛(上海)G-Fibonacci
第 45 届ICPC亚洲区域赛(上海)G-Fibonacci
2022-08-02 00:13:00 【ZaneBobo】
题意:
题目链接(牛客网)点此查看原英文题目
你现在有一串斐波那契数列,然后定义一个g(x,y),如果x*y为偶数那么g(x,y)是1,否则的话是0,现在给你一个n,让你求。
思路:
规律题,我们发现斐波那契数列是“奇奇偶奇奇偶”的一个规律三个一循环,然后再利用奇数偶数=偶数,奇数奇数=奇数,偶数偶数=偶数这个性质,计算就可以了。
代码:
#include<iostream>
using namespace std;
typedef long long LL;
int main()
{
long long n;
cin>>n;
long long a=n/3,aa=n%3;
long long sum1=a*2+aa,sum2=a;//sum1是奇数的个数,sum2是偶数的个数
LL sum=0;
sum+=sum1*sum2+sum2*(sum2-1)/2;//计算公式前面的奇数与偶数相乘的所有情况
//后面是偶数与偶数相乘的所有情况,后面用到了等差求和。
cout<<sum<<endl;
}
这题因为long long wa了好多次,后来才知道(LL)(a+b)和((LL)a+(LL)b)根本不一样,前者只是把计算过后的a+b转化成LL 而此时a+b很有可能已经溢出了,后面则是转化后再相加,不会溢出。
看来学好语法基础知识很重要呀!
边栏推荐
- 辨析内存函数memset、memcmp、memmove以及memcpy
- uni-app项目总结
- Identify memory functions memset, memcmp, memmove, and memcpy
- Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
- [21-Day Learning Challenge] A small summary of sequential search and binary search
- 微软电脑管家V2.1公测版正式发布
- ROS 动态参数
- 【解决】win10下emqx启动报错Unable to load emulator DLL、node.db_role = EMQX_NODE__DB_ROLE = core
- Trie详解
- Don't know about SynchronousQueue?So ArrayBlockingQueue and LinkedBlockingQueue don't and don't know?
猜你喜欢
Redis-消息发布订阅
String splitting function strtok exercise
Double queue implementation stack?Dual stack implementation queue?
A simple file transfer tools
CVPR 2022 | SharpContour:一种基于轮廓变形 实现高效准确实例分割的边缘细化方法
Using the "stack" fast computing -- reverse polish expression
Redis - message publish and subscribe
Knowing the inorder traversal of the array and the preorder traversal of the array, return the postorder history array
MLX90640 红外热成像仪测温传感器模块开发笔记(十) 成果展示-红眼睛相机
BGP first experiment
随机推荐
unity2D横版游戏教程5-UI
辨析内存函数memset、memcmp、memmove以及memcpy
Play NFT summer: this collection of tools is worth collecting
Interview high-frequency test questions solution - stack push and pop sequence, effective parentheses, reverse Polish expression evaluation
路由策略
Task execution control in Ansible
实现删除-一个字符串中的指定字母,如:字符串“abcd”,删除其中的”a”字母,剩余”bcd”,也可以传递多个需要删除的字符,传递”ab”也可以做到删除”ab”,剩余”cd”。
Detailed explanation of JSP request object function
Stapler:1 靶机渗透测试-Vulnhub(STAPLER: 1)
Kotlin协程:创建、启动、挂起、恢复
Redis-消息发布订阅
Identify memory functions memset, memcmp, memmove, and memcpy
以交易为生是一种什么体验?
[HCIP] BGP Small Experiment (Federation, Optimization)
Double queue implementation stack?Dual stack implementation queue?
Unknown CMake command “add_action_files“
Microsoft PC Manager V2.1 beta version officially released
含外部储能的电力系统暂态稳定分布式控制
String splitting function strtok exercise
基于相关性变量筛选偏最小二乘回归的多维相关时间序列建模方法