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

中国上海网外贸谷歌优化

中国上海网,外贸谷歌优化,百度商桥置入网站,定制v软件1、模拟 2、贪心 3、前缀和 4、猜结论 5、双指针 6、期望DP&#xff08;公式有问题已更改&#xff09; 1. 蘑菇炸弹 思路&#xff1a;一个简单的暴力模拟。 #include <bits/stdc.h> using namespace std; int main() {int n;cin >> n;vector<int>a(n…

1、模拟

2、贪心

3、前缀和

4、猜结论

5、双指针

6、期望DP(公式有问题已更改)

1. 蘑菇炸弹
 

        

思路:一个简单的暴力模拟。

        

#include <bits/stdc++.h>
using namespace std;
int main()
{int n;cin >> n;vector<int>a(n , 0);for(int i = 0 ; i < n ; i ++)cin >> a[i];int cnt = 0;for(int i = 1 ; i < n - 1; i ++){if(a[i] >= a[i - 1] + a[i + 1])cnt++;}cout << cnt;return 0;
}

2. 构造数字

        

       思路:考虑正整数中每一位的贡献:可以发现位数越大的位置贡献越大,因此将M优先分配给高位即可。

        

#include <bits/stdc++.h>
using namespace std;
int main()
{int n , m;cin >> n >> m;for(int i = 0 ; i < n ; i ++){int x = min(m , 9);cout << x;m -= x;}return 0;
}

3. 小蓝的金牌梦

思路: 首先考虑若已知长度为x,如何快速求出子数组最大值,可以用前缀和来O(1)的去解决,然后遍历所有的子数组左端点,时间复杂度总共O(N - X)。接下来考虑所有质数情况:

10^5范围内的质数共有9592个,考虑遍历所有情况:总共的复杂度为O(10^5 * 9592 - \sum prime)约为5e^8,直接暴力做还是能过的,所以直接暴力冲就行。

        

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 1e09+7;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
vector<LL>prime;//存储素数
bool vis[N+5];
void su() 
{for(int i=2;i<=N;i++){if(!vis[i])prime.pb(i);for(int j=0;j < prime.size() && prime[j] * i <= N;j ++){vis[prime[j]*i]=1;if(i % prime[j]==0)break;}}
} 
void solve() 
{cin >> n;int sum[n + 5];sum[0] = 0;for(int i = 1 ; i <= n ; i ++)cin >> a[i] , sum[i] = sum[i - 1] + a[i];int maxx = -1e9;for(int i = 0 ; i < prime.size() ; i ++){int len = prime[i];if(len > n){break;}for(int j = len ; j <= n ; j ++){maxx = max(maxx , sum[j] - sum[j - len]);}}cout << maxx;
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;su();//cin>>t;while(t--){solve();}return 0;
}

 4. 合并石子加强版

        

        思路:若只关注一个石头:发现最终他的贡献为其自身权值与其他所有石头权值乘积之和。而其他所有石头也是一样的。因此最终的代价和合并石子的顺序无关,只需要按顺序模拟即可。(longlong会爆,需要unsigned long long )

        

#include <iostream>
using namespace std;
#define int unsigned long long
signed main()
{int n;cin >> n;int a[n];for(int i = 0 ; i < n ; i ++)cin >> a[i];int sum = a[0];int tot = 0;for(int i = 1 ; i < n ; i ++){tot += a[i] * sum;sum += a[i];}cout << tot;return 0;
}

 5. 简单的LIS问题

       

思路:可以发现:修改一个数之后的效果最多能够使得LIS增加1。接下来考虑怎么添加能保证上升子序列增加1:

1、若当前上升子序列不包含最后一个元素,那么将最后一个元素设为10^{100}就一定能使得上升子序列加一。

2、若上升子序列的开头不为0且不为第一个数,那么将第一个数改为0就一定能使得上升子序列增加1。

3、修改子序列中相邻两个数a_{b_{i}} a_{b_{i + 1}}之间的某个数,使得a_{b_{i}} < a_x < a_{b_{i +1}}(b_{i} < x < b_{i + 1})

所以我们需要知道的是:以某个数开头往后所能形成的最长上升子序列以及以某个数结尾能够形成的最长上升子序列。分别设为l[i]以及r[i],对应了以a_{i}结尾能够形成最长上升子序列长度以及以a_{i}开头能够形成的最长上升子序列长度。

对于情况1和情况2,可以直接通过l,r函数来求解,对于情况3,可以想到将lr合并,即最长上升子序列长度为l[i] + r[j] (i <j \ and \ a[i] < a[j]),当j - i > 2 \ and \ a[j] - a[i] >= 2时,则能够在[i , j]之间修改一个数使得LIS增加1。

        

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,ans;
int a[5001],l[5001],r[5001];
signed main()
{cin >> n;for(int i = 1 ; i <= n ; i ++)cin >> a[i];for(int i = 1 ; i <= n ; i ++){l[i] = r[i] = 1;}for(int i = 2 ; i <= n ; i ++){for(int j = 1 ; j < i ; j ++){if(a[i] > a[j])l[i] = max(l[i] , l[j] + 1);}}for(int i = n ; i >= 1 ; i --){for(int j = n ; j > i ; j --){if(a[i] < a[j])r[i] = max(r[i] , r[j] + 1);}}for (int i = 1;i <= n ; i ++){if(i < n){//等效于将末尾设为10^1000ans = max(ans , l[i] + 1);}else{ans = max(ans , l[i]);}if(i != 1 && a[i] != 0){//等效于将 a1 设为0ans = max(ans , r[i] + 1);}else{ans = max(ans , r[i]);}for(int j = i + 2 ; j <= n ; j ++)//等效于将i ~ j 当中的一个数设为ai + 1if (a[j] - a[i] > 1)ans = max(ans , l[i] + r[j] + 1);}cout << ans;
}

6. 期望次数

思路:一道期望DP的板子题,定义DP[i]为当前x = i 时,需要达到目标M的操作期望。

定义SUM为权值总和,定义a[i]为将x * i 的权值。

        接下来考虑转移方程:dp[i] = 1 + ((\sum_{j = 1} ^{n} a_{j} * (dp[i * j])(i * j < M))/sum)

        化简之后得到:dp[i] = (sum +(\sum_{j = 2} ^{n} a_{j} * (dp[i * j])(i * j < M)) / (sum - a[1])

    之后就从后往前DP即可,最终输出DP[1].

#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define pb push_back
#define x first
#define y second 
#define endl '\n'
#define int long long
const LL maxn = 4e05+7;
const LL N = 5e05+10;
const LL mod = 998244353;
const int inf = 0x3f3f3f3f;
const LL llinf = 5e18;
typedef pair<int,int>pl;
priority_queue<LL , vector<LL>, greater<LL> >mi;//小根堆
priority_queue<LL> ma;//大根堆
LL gcd(LL a, LL b){return b > 0 ? gcd(b , a % b) : a;
}LL lcm(LL a , LL b){return a / gcd(a , b) * b;
}
int n , m;
vector<int>a(N , 0);
void init(int n){for(int i = 0 ; i <= n ; i ++){a[i] = 0;}
}
LL qpow(LL a , LL b)//快速幂
{LL sum=1;while(b){if(b&1){sum=sum*a%mod;}a=a*a%mod;b>>=1;}return sum;
}
int dp[N];//从i到最终状态的期望次数
//sum - a[1] / sum dp[i] = Σ(dp[i * j] * a[i * j] / sum) + 1
// dp[i] = Σdp[i * j] * a[i * j] + sum / sum - a[i]
void solve() 
{cin >> n >> m;int sum = 0;for(int i = 1 ; i <= n ; i ++){cin >> a[i];sum += a[i];}for(int i = m - 1 ; i >= 1 ; i --){for(int j = 2 ; j <= n && j * i < m ; j ++){dp[i] += a[j] * dp[i * j];dp[i] %= mod;}dp[i] += sum;dp[i] %= mod;dp[i] *= qpow(sum - a[1] , mod - 2);dp[i] %= mod;}cout << dp[1];
}            
signed main() 
{ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);int t=1;
//	cin>>t;while(t--){solve();}return 0;
}

http://www.yayakq.cn/news/213013/

相关文章:

  • 想创办一个本地的人才招聘网站_如何做市场调查问卷做质粒图谱的网站
  • 网站上线具体流程什么什么云用来做网站
  • win10 中国建设银行网站湛江seo推广公司
  • 装修公司网站建设费用奉贤高端网站建设
  • 定制网站开发公司排名清远市网站建设公司
  • 做电商有哪些网站有哪些新出网页游戏
  • 红酒网站建设方案做网站的职员称呼什么
  • 有什么可以做兼职的网站网站优化需要什么软件
  • 余姚市城乡建设局网站成都企业网站建设
  • 怎样建网站什么网站专门做外围的
  • 在哪个网站上做蓝思测评wordpress app 主题
  • 网站开发电脑设置地方网站发展方向
  • 药品网站建设存在的问题美的公司网站建设的目的
  • 网站 空间 域名杭州seo渠道排名
  • asp.net构建门户网站南山网站建设乐云seo
  • 手机网站加百度商桥平面设计师求职网
  • 网页设计个人网站做购物网站公司
  • 做it的在哪个网站找工作中国纪检监察报评论员文章
  • 我的网站织梦妇科医院免费的咨询
  • 三乡网站建设公司wordpress 中文 主题
  • 一级域名网站wordpress固定链接 404
  • 企业营销网站建设的基本步骤重庆市建设工程信息网南川区
  • 网站建设书籍如何做网站的教程
  • wordpress最详细的教程视频教程郑州seo外包公司哪家好
  • 广告案例网站wordpress注册没有密码错误
  • 公司网站建设佛山哪家哪有网站建设明细报价表
  • 拉米拉云网站建设godaddy的wordpress主机
  • wordpress首页只显示标题seo全网推广营销软件
  • 用asp.net做的购物网站悬停显示 wordpress
  • 如何做微信ppt模板下载网站阿里巴巴国际站官网首页