Codeforces Round #603 (Div. 2) ABC 题解
A. Sweet Problem
题意:有三个数,每次可以选两个-1,问最多能挑多少次。
思路:贪心一下。策略如下:
1.先将三个数排个序。
2.然后如果最大的和次大的不一样多的话,就让最大的和最小的一起减少,尽量减少到和次大的一样大。
3.然后a[2]和a[3]一样大时,若a[1]还有剩的,就和a[2]、a[3]均分一下,多出来的随便给。
4.最后a[2]和a[3]一起减少。贡献取最小值。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
ll a[5];
int main()
{
int kase;
cin>>kase;
while(kase--)
{
cin>>a[1]>>a[2]>>a[3];
sort(a+1,a+1+3);
ll ans = 0;;
if(a[3] > a[2])
{
ll d = min(a[1], a[3] - a[2]);
ans += d;
a[3] -= d;
a[1] -= d;
}
if(a[3]==a[2]&&a[1])
{
ll d = a[1] /2 ;
ans += d*2;
ans += a[1]%2;
a[3] -= a[1]%2;
a[3] -= d, a[2] -= d;
}
ans += min(a[2], a[3]);
cout<<ans<<endl;
}
return 0;
}
B. PIN Codes
题意,给你n个数,问你最小改变他们中多少个位,才能使得全部都不一样。
发现n最大也就10。所以我们只需要考虑个位即可。如果前三位都一样,我们就改变个位。若前三位有不一样的,就不需要改。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
map<string, int> Map;
int main()
{
int kase;
cin>>kase;
while(kase--)
{
vector<string> s;
Map.clear();
int n; cin>>n;
rep(i,1,n)
{
string tmp;
cin>>tmp;
s.pb(tmp);
Map[tmp]++;
}
int cnt = 0;
rep(i,1,n)
{
string cur = s[i-1];
if(Map[cur]>1)
{
for(int j=0; j<=9; j++)
{
s[i-1][3] = j + '0';
if(!Map[s[i-1]])
{
cnt++;
Map[s[i-1]] ++;
Map[cur] --;
break;
}
}
}
}
cout<<cnt<<'\n';
rep(i,1,n) cout<<s[i-1]<<'\n';
}
return 0;
}
C. Everyone is a Winner!
题意:问你 \(\lfloor n/1 \rfloor\), \(\lfloor n/2 \rfloor\), \(\lfloor n/3 \rfloor\) ..... \(\lfloor n/n \rfloor\), \(\lfloor n/(n+1) \rfloor\) 共有多少种不同的数。
其实这是整数分块的模板题了。如果直接遍历的话是O(n)的时间复杂度,必超时。
我们发现,如n = 100时, n/20 = 5, n/21 = n/22 = n/23 = n/24 = n/25 = 4,像[21,25]完全不用再遍历的。我们在到i=21时,就可以知道商为4时最远能到哪里——能到(n/(n/21)) = 25,所以下次遍历的时候直接从25开始即可。 这便是整数分块的思想。详见代码,时间复杂度O(\(\sqrt{n}\))。
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include <unordered_map>
#include <queue>
#include<sstream>
#include <stack>
#include <set>
#include <bitset>
#include<vector>
#define FAST ios::sync_with_stdio(false)
#define abs(a) ((a)>=0?(a):-(a))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mem(a,b) memset(a,b,sizeof(a))
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
const int maxn = 1e5+200;
const int inf=0x3f3f3f3f;
const double eps = 1e-7;
const double pi=acos(-1.0);
const int mod = 1e9+7;
inline int lowbit(int x){return x&(-x);}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
void ex_gcd(ll a,ll b,ll &d,ll &x,ll &y){if(!b){d=a,x=1,y=0;}else{ex_gcd(b,a%b,d,y,x);y-=x*(a/b);}}//x=(x%(b/d)+(b/d))%(b/d);
inline ll qpow(ll a,ll b,ll MOD=mod){ll res=1;a%=MOD;while(b>0){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
inline ll inv(ll x,ll p){return qpow(x,p-2,p);}
inline ll Jos(ll n,ll k,ll s=1){ll res=0;rep(i,1,n+1) res=(res+k)%i;return (res+s)%n;}
inline ll read(){ ll f = 1; ll x = 0;char ch = getchar();while(ch>'9'||ch<'0') {if(ch=='-') f=-1; ch = getchar();}while(ch>='0'&&ch<='9') x = (x<<3) + (x<<1) + ch - '0', ch = getchar();return x*f; }
int dir[4][2] = { {1,0}, {-1,0},{0,1},{0,-1} };
vector<ll> res;
void solve(ll n)
{
for(ll l=1,r=0; l<=n; l = r+1)
{
res.pb(n/l);
r = (n/ (n/l));
}
}
int main()
{
int kase;
cin>>kase;
while(kase--)
{
res.clear();
ll n = read();
solve(n); res.pb(0);
sort(res.begin(),res.end());
cout<<res.size()<<'\n';
for(int i=0; i<res.size();i++)
cout<<res[i]<<' ';
cout<<'\n';
}
return 0;
}
Codeforces Round #603 (Div. 2) ABC 题解的更多相关文章
- Codeforces Round #312 (Div. 2) ABC题解
[比赛链接]click here~~ A. Lala Land and Apple Trees: [题意]: AMR住在拉拉土地. 拉拉土地是一个很漂亮的国家,位于坐标线.拉拉土地是与著名的苹果树越来 ...
- # Codeforces Round #529(Div.3)个人题解
Codeforces Round #529(Div.3)个人题解 前言: 闲来无事补了前天的cf,想着最近刷题有点点怠惰,就直接一场cf一场cf的刷算了,以后的题解也都会以每场的形式写出来 A. Re ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
- Codeforces Round #603 (Div. 2) A. Sweet Problem(水.......没做出来)+C题
Codeforces Round #603 (Div. 2) A. Sweet Problem A. Sweet Problem time limit per test 1 second memory ...
- Codeforces Round #540 (Div. 3) 部分题解
Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...
- Codeforces Round #538 (Div. 2) (A-E题解)
Codeforces Round #538 (Div. 2) 题目链接:https://codeforces.com/contest/1114 A. Got Any Grapes? 题意: 有三个人, ...
- Codeforces Round #531 (Div. 3) ABCDEF题解
Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...
- Codeforces Round #527 (Div. 3) ABCDEF题解
Codeforces Round #527 (Div. 3) 题解 题目总链接:https://codeforces.com/contest/1092 A. Uniform String 题意: 输入 ...
- Codeforces Round #499 (Div. 1)部分题解(B,C,D)
Codeforces Round #499 (Div. 1) 这场本来想和同学一起打\(\rm virtual\ contest\)的,结果有事耽搁了,之后又陆陆续续写了些,就综合起来发一篇题解. B ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- eolinker请求预处理:请求数据中有中文,提示参数错误的解决方法
特别注意:需要使用全局变量或者预处理前务必阅读本链接https://www.cnblogs.com/becks/p/13713278.html 如下图,请求参pageName参数为中文,提交后报错 需 ...
- 题解:AT_arc173_a [ARC173A] Neq Number
简单二分. 思路 数位 dp 预处理和判断. init 预处理出 dp 数组,与 windy 数大致相同. 二分答案,如果 111 至 midmidmid 的 Neq 数数量大于等于 kkk,rt=m ...
- Nacos简介—4.Nacos架构和原理
Nacos简介-4.Nacos架构和原理 大纲 1.Nacos的定位和优势 2.Nacos的整体架构 3.Nacos的配置模型 4.Nacos内核设计之一致性协议 5.Nacos内核设计之自研Dist ...
- 毒瘤idea合集
给定 \(n,m\) ,求: \[\sum_{i=1}^{n}\sum_{i=1}^{m}max\big(gcd(i,j)^i,lcm(i,j)^j\big) \]
- 【笔记】Python3|(一)Python 申请并调用国内百度、阿里、腾讯、有道的翻译 API 的教程和测试情况(第三方库 translate 和 腾讯 API 篇)
var code = "dccf4c95-7458-4b38-b8ae-d45b3e59c218" 价格和 API 申请参考: 免费翻译接口最新最全汇总(百度翻译,腾讯翻译,谷歌翻 ...
- 【HUST】网络攻防实践|TCP会话劫持+序列号攻击netcat对话
文章目录 一.前言 1. 实验环境 2. 攻击对象 3. 攻击目的 4. 最终效果 docker的使用 新建docker docker常用指令 二.正式开始 过程记录 1. ARP欺骗 2. 篡改数据 ...
- 自荐:开源截图工具ScreenCapture:超多控制指令,支持截长图
特性 跨屏幕截图.滚动截图(截长图).高分屏支持.窗口区域高亮. 取景框,快捷键复制 RGB 颜色(Ctrl+R). HEX 颜色(Ctrl+H)与 CMYK 颜色(Ctrl+K). 绘制填充.非填充 ...
- 20250528 - Usual 攻击事件: 价差兑换与请君入瓮
背景信息 项目背景 VaultRouter 合约有用特权身份,可以通过 Usd0PP 合约将 USD0++ 以 1:1 的比例兑换成 USD0,随后通过 UniV3 将 USD0 swap 成 sUS ...
- 「Note」模板速查
代码 #include <bits/stdc++.h> using namespace std; typedef long long LL; typedef unsigned long l ...
- 安卓手机上部署nodejs服务器
一.准备软件 Termux 下载地址: 链接:https://pan.baidu.com/s/1J3OQITWc34uT-Mc8B-moPA?pwd=ug9j 提取码:ug9j KSW ...