A

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 3e7 + ;
const int maxm = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll mod = 1e9 + ;
int main()
{
int x, y;
cin >> x >> y;
if (x == || y == )
{
if (x == && y == )
{
cout << "Yes" << endl;
}
else
{
cout << "No" << endl;
}
return ;
}
int cur = y - ;
int remain = x - cur;
if (remain % == && cur && remain>=)
{
cout << "Yes" << endl;
return ;
}
cout << "No" << endl;
return ;
}

B

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
int num[];
int cnt;
bool check(int a, int b, int c)
{
if (a + b > c && a + c > b && b + c > a)
{
return true;
}
return false;
}
int main()
{
int n;
int anser = ;
cin >> n;
for (int i = ; i < n; i++)
{
for (int j = i + ; j <= n; j++)
{
int aim = (i ^ j);
if (aim >= j && aim <= n && check(i, j, aim))
{
//cout << i << " " << j << " " << aim << endl;
anser++;
}
}
}
cout << anser << endl;
return ;
}

C

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxn = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
int main()
{
//freopen("sample.txt", "w", stdout);
ll n, k;
cin >> n >> k;
if (n == && k <= )
{
cout << "Yes" << endl;
return ;
}
if (k >= n)
{
cout << "No" << endl;
}
else
{
for (ll i = ; i <= min(1LL * , k); i++)
{
if (n % i != i - )
{
cout << "No" << endl;
return ;
}
}
cout << "Yes" << endl;
}
return ;
}

D

奇葩贪心题 假设有两个字符串A B A在B前面的条件是什么?

假设A有SHa个sh BSHb A有Sa个s BSb A有Ha个h BHb 当 SHa+SHb+Sa*Hb>SHa+SHb+Sb*Ha 时成立

转换一下就是A的sh比例比B高的时候 A在B前面

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxn = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
struct node
{
string str;
double per;
} s[];
bool operator <(node a, node b)
{
return a.per > b.per;
}
ll pre[];
string aim = "";
int main()
{
ll anser = ;
//freopen("sample.txt", "w", stdout);
int n;
cin >> n;
for (int i = ; i <= n; i++)
{
int now = ;
cin >> s[i].str;
int len = s[i].str.size();
for (int j = ; j < len; j++)
{
if (s[i].str[j] == 's')
{
now++;
}
}
if (len - now == )
{
s[i].per = ;
}
else
{
s[i].per = (double)now / (double)(len - now);
}
//cout << s[i].per << endl;
}
sort(s + , s + + n);
for (int i = ; i <= n; i++)
{
aim += s[i].str;
}
//cout << aim << endl;
int lenth = aim.size();
for (int i = ; i < lenth; i++)
{
if (i == )
{
pre[i] = (aim[i] == 's');
}
else
{
pre[i] = pre[i - ] + (aim[i] == 's');
}
if (aim[i] == 'h')
{
anser += pre[i];
}
}
cout << anser << endl;
return ;
}

E

一般想到的DP思路是DP[i][j]表示前i个用了j块钱能吸引多少鸟 但是这里j太大了(于是题目就提示你C[i]的总值不超过10000)

所以用DP[i][j]表示在前i个吸引了j个鸟最多好剩多少魔力   复杂度:   前面的复杂度是pre[i]较小的时候 后面是pre[i]较大的时候

DP方程:

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int maxn = ;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
const int turn2[][] = {{, }, { -, }, {, }, {, -}, {, -}, { -, -}, {, }, { -, }};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll n, W, B, X;
ll c[];
ll pre[];
ll cost[];
ll dp[][];
int main()
{
//freopen("sample.txt", "w", stdout);
// W初始值 B增加的上限 X回复的数目
mem(dp, -);
cin >> n >> W >> B >> X;
dp[][] = W;
for (int i = ; i <= n; i++)
{
cin >> c[i];
pre[i] = pre[i - ] + c[i];
}
for (int i = ; i <= n; i++)
{
cin >> cost[i];
}
for (ll i = ; i <= n; i++)
{
for (ll j = ; j <= pre[i]; j++)
{
for (ll k = ; k <= min(j, c[i]); k++)
{
if (dp[i - ][j - k] == - || 1LL * cost[i]*k > dp[i - ][j - k])
{
continue;
}
dp[i][j] = max(dp[i][j], dp[i - ][j - k] - 1LL * k * cost[i]);
}
if (dp[i][j] != -)
{
dp[i][j] = min(dp[i][j] + X, W + 1LL * j * B);
}
}
}
for (int i = pre[n]; i >= ; i--)
{
if (dp[n][i] >= )
{
cout << i << endl;
return ;
}
}
return ;
}

F

先N*lnN处理出每个数的被除数个数 然后做前缀和 如果K>dp[N] 就无解

所以猜测 当dp[i]>=k时即有解 当数据大于10时 dp数列每两个之间相差不会超过各自之下的i/2+1~i的质数个数(为什么选i/2~i的质数是因为其sum[i]只为1 方便调整)

所以当N>10的时候找到最小的满足dp[i]>=k的i 然后用删去其i/2+1~i之间的质数来调整 dp[i]-k

后来知道 当N<=10的时候 也满足>10的解法  一个数N的被整除数在N^(1/3)数量级 质数则在 N/LogN数量级

#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que; get min
const double eps = 1.0e-10;
const double EPS = 1.0e-4;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
//const int maxn = 3e5 + 10;
const int turn[][] = {{, }, { -, }, {, }, {, -}};
//priority_queue<int, vector<int>, less<int>> que;
//next_permutation
ll Mod = ;
vector<int> prime;
int n;
ll k;
int anserten;
ll sum[];
ll dp[];
int visit[];
void dfs(int pos, int x)
{
if (pos == n + )
{
if (anserten == )
{
int now = ;
for (int i = ; i <= ; i++)
{
if (x & ( << i))
{
for (int j = i * ; j <= ; j += i)
{
if (x & ( << j))
{
//cout << i << " " << j << endl;
now++;
}
}
}
}
if (now == k)
{
anserten = x;
}
}
return ;
}
dfs(pos + , x + ( << pos));
dfs(pos + , x);
}
priority_queue<pair<int, int> > que;
int main()
{
cin >> n >> k;
for (int i = ; i <= n; i++)
{
for (int j = i * ; j <= n; j += i)
{
sum[j]++;
}
}
for (int i = ; i <= n; i++)
{
dp[i] = dp[i - ] + sum[i];
}
if (k > dp[n])
{
cout << "No" << endl;
return ;
}
else
{
cout << "Yes" << endl;
if (n <= )
{
dfs(, );
int anser = ;
for (int i = ; i <= ; i++)
{
if (anserten & ( << i))
{
anser++;
}
}
cout << anser << endl;
for (int i = ; i <= ; i++)
{
if (anserten & ( << i))
{
cout << i << " ";
}
}
cout << endl;
}
else
{
dp[n + ] = INT_MAX;
int aim;
for (aim = ; aim <= n; aim++)
{
if (dp[aim] >= k && dp[aim - ] < k)
{
break;
}
}
int anser = aim;
for (int i = aim; i >= ; i--)
{
visit[i] = ;
}
for (int i = aim; i >= aim / + ; i--)
{
que.push({sum[i], i});
}
int cha = dp[aim] - k;
pair<int, int> cnt;
while (cha > )
{
cnt = que.top();
que.pop();
if (cnt.first <= cha)
{
cha -= cnt.first;
visit[cnt.second] = ;
anser--;
}
}
cout << anser << endl;
for (int i = ; i <= aim; i++)
if (visit[i])
{
cout << i << " ";
}
cout << endl;
}
}
return ;
}

Codeforces 922 思维贪心 变种背包DP 质因数质数结论的更多相关文章

  1. Codeforces 922 E Birds (背包dp)被define坑了的一题

    网页链接:点击打开链接 Apart from plush toys, Imp is a huge fan of little yellow birds! To summon birds, Imp ne ...

  2. Codeforces 730J:Bottles(背包dp)

    http://codeforces.com/problemset/problem/730/J 题意:有n个瓶子,每个瓶子有一个当前里面的水量,还有一个瓶子容量,问要把所有的当前水量放到尽量少的瓶子里至 ...

  3. codeforces 148E Aragorn's Story 背包DP

    Aragorn's Story Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/probl ...

  4. Buy Low Sell High CodeForces - 867E (思维,贪心)

    大意: 第i天可以花$a_i$元买入或卖出一股或者什么也不干, 初始没钱, 求i天后最大收益 考虑贪心, 对于第$x$股, 如果$x$之前有比它便宜的, 就在之前的那一天买, 直接将$x$卖掉. 并不 ...

  5. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  6. Codeforces Codeforces Round #319 (Div. 2) B. Modulo Sum 背包dp

    B. Modulo Sum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/577/problem/ ...

  7. 0-1背包的动态规划算法,部分背包的贪心算法和DP算法------算法导论

    一.问题描述 0-1背包问题,部分背包问题.分别实现0-1背包的DP算法,部分背包的贪心算法和DP算法. 二.算法原理 (1)0-1背包的DP算法 0-1背包问题:有n件物品和一个容量为W的背包.第i ...

  8. 【bzoj4922】[Lydsy六月月赛]Karp-de-Chant Number 贪心+背包dp

    题目描述 给出 $n$ 个括号序列,从中选出任意个并将它们按照任意顺序连接起来,求以这种方式得到匹配括号序列的最大长度. 输入 第一行包含一个正整数n(1<=n<=300),表示括号序列的 ...

  9. E. The Contest ( 简单DP || 思维 + 贪心)

    传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...

随机推荐

  1. 监听浏览器返回键、后退、上一页事件(popstate)操作返回键

    在WebApp或浏览器中,会有点击返回.后退.上一页等按钮实现自己的关闭页面.调整到指定页面.确认离开页面或执行一些其它操作的需求.可以使用 popstate 事件进行监听返回.后退.上一页操作. 一 ...

  2. Powershell + HTA

    众所周知,Powershell早已被集成到了windows的环境中,国外大牛玩得不亦乐乎,而国内圈子却很少听到讨论Powershell的,HTA更不用说了,不是学计算机的或许根本不知道这是什么鬼 Li ...

  3. k8s 添加ingress 暴露服务

    vim file.yaml apiVersion: extensions/v1beta1 kind: Ingress metadata: name: pgadmin labels: k8s-app: ...

  4. 一、Python环境的搭建

    1.python官方下载地址:https://www.python.org/:python现在有两个版本:python2.7.x和python3.x 2.安装:一路下一步,默认安装 3.配置环境变量: ...

  5. Python Module_openpyxl_styles 样式处理

    目录 目录 前言 系统软件 Working with styles Styles can be applied to the following aspects Styles模块 Copying st ...

  6. Delphi XE2 之 FireMonkey 入门(40) - 控件基础: TMemo

    Delphi XE2 之 FireMonkey 入门(40) - 控件基础: TMemo 值得注意的变化: 1.其父类 TScrollBox 的许多特性也很有用处, 如:   Memo1.UseSma ...

  7. 5.2.k8s.Secret

    #Secret Secret存储密码.token.密钥等敏感数据 Secret以Volume或环境变量方式使用 #Secret类型 Opaque : base64 编码格式的 Secret kuber ...

  8. 编写Python脚本把sqlAlchemy对象转换成dict的教程

    编写Python脚本把sqlAlchemy对象转换成dict的教程 在用sqlAlchemy写web应用的时候,经常会用json进行通信,跟json最接近的对象就是dict,有时候操作dict也会比操 ...

  9. Git配置用户名、邮箱

    当安装完 Git 应该做的第一件事就是设置你的用户名称与邮件地址. 这样做很重要,因为每一个 Git 的提交都会使用这些信息,并且它会写入到你的每一次提交中,不可更改. 否则,用户名会显示为unkno ...

  10. 11g Oracle Rac安装(基于linux6)

    安装 Oracle 11gR2 RAC on Linux 6 本文介绍如何在Oracle Linux 6上安装2节点Oracle 11gR2 Real Application Cluster(RAC) ...