cf560
A
题意 给你一个 2e5的01串 和 x y要求这个串%10^x = 10 ^ y
那么按照题意模拟 都变成0 那位变成1 即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
char str[MAX_N];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n,x,y,ans = 0;
scanf("%d%d%d",&n,&x,&y);
scanf("%s",str+1);
for(int i = n;i>=n-y+1;--i) if(str[i]!='0') ans++;
if(str[n-y]!='1') ans++;
for(int i = n-y-1;i>n-x;i--) if(str[i]!='0') ans++;
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
B
题意 每天要买 当天天数个商品
问你这些商品能最多连续买几天
用优先队列模拟即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
int arr[MAX_N];
priority_queue<int>q;
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n,ans = 0,now = 1;
scanf("%d",&n);
for(int i = 1;i<=n;++i) scanf("%d",&arr[i]),q.push(-arr[i]);
while(1)
{
if(q.empty()) break;
int top = -q.top();
q.pop();
while(top<now&&!q.empty())
{
top = -q.top();
q.pop();
}
if(top>=now) ans++,now++;
else break;
}
printf("%d\n",ans);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
C
题目定义了一个好串 就是一定是偶数长度
然后奇数位的字符不等于下一个位的字符
那么我们发现只要把不相等的取过来即可
如果有多个相等 就留一个下来
代码如下
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
char str[MAX_N];
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n,ans=0;
scanf("%d",&n);
scanf("%s",str+1);
int len = strlen(str+1);
for(int i = 1;i<n;++i)
{
if(str[i]!=str[i+1])
{
str[++ans] = str[i];
str[++ans] = str[i+1];
i++;
}
}
str[ans+1] = '\0';
printf("%d\n",n-ans);
printf("%s\n",str+1);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
D
题意 给你一个数除了 1 和他本身的所有约数
让你输出最小的这个数
用两个vector 模拟即可
因为他约数乘积一定是对应 小的 乘 大的
Wa点是可能没给满 比如 16 他给你 2 8 你会跑出来 16 其实 4 也必须在
所以再sqrt(ans)枚举一下 VT 判容量是否相等
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
vector<int > vt,vt_;
ll ans ;
int arr[355];
bool check()
{
set<long long > st;
int sz = vt.size();
int tmp = sz/2;
if(sz%2==1)
{
for(int i = 0;i<tmp;++i)
{
st.insert(1ll*vt[i]*vt_[i]);
ans = 1ll*vt[i]*vt_[i];
}
st.insert(1ll*(vt[tmp])*(vt[tmp]));
ans = 1ll*(vt[tmp])*(vt[tmp]);
if(st.size()==1)
{
return true;
}
return false;
}
else
{
for(int i = 0;i<tmp;++i)
{
st.insert(1ll*vt[i]*vt_[i]);
ans = 1ll*vt[i]*vt_[i];
}
if(st.size()==1)
{
return true;
}
return false;
}
}
bool Comp(const int &a, const &b)
{
return a>b;
}
vector<int> VT;
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int t;
scanf("%d",&t);
while(t--)
{
vector<int> vt__,vt___,VT_;
swap(vt,vt__),swap(vt_,vt___),swap(VT,VT_);
int n;
scanf("%d",&n);
for(int i = 1;i<=n;++i)
scanf("%d",&arr[i]),vt.push_back(arr[i]),vt_.push_back(arr[i]);
sort(vt.begin(),vt.end());
sort(vt_.begin(),vt_.end(),Comp);
if(check())
{
for(long long i = 2;i*i<=ans;++i)
{
if(ans%i==0)
{
VT.push_back(i);
if(ans/i!=i) VT.push_back(ans/i);
}
}
if(VT.size()!=vt.size()) printf("-1\n");
else printf("%lld\n",ans);
}
else printf("-1\n");
}
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
E
容易发现每一位的 a[i] * b[i] 实际上加了 (n+1-i)*i 次
那么把他和 a[i] 数组想乘后得到 tmp 数组
tmp数组大与 brr数组小的数想乘就能得到最小的积和了
sort 即可
注意溢出
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int) 998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
unsigned long long arr[200025],brr[200025],tmp[200025];
unsigned long long now[200025],tmp_[200025];
map<unsigned long long ,int >mp;
bool cmp(unsigned long long a,unsigned long long b)
{
return a >b;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int n;
cin >> n;
unsigned long long ans = 0;
for(int i = 1;i<=n;++i) cin >> arr[i];
for(int i = 1;i<=n;++i) cin >> brr[i];
for(int i = 1;i<=n;++i)
{
now[i] = 1ll*(n+1-i)*(i);
tmp[i] = now[i]*arr[i],tmp_[i] = tmp[i];
}
sort(tmp_+1,tmp_+1+n);
sort(brr+1,brr+1+n,cmp);
for(int i = 1;i<=n;++i)
{
ans = (ans+tmp_[i]%mod*brr[i]%mod)%mod;
}
cout << ans << endl;
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}
F1,F2
F1,F2同题
题意就是你每天可以获得一个硬币
如果某个商品在打折 你可以花一个硬币买
否则需要花两个硬币买
问你最少多少天可以买完要求的n个物品 每个物品不一定多少个
我们首先看到数据范围要想到二分这个答案 因为这个答案具有单调性 小的天数能满足 大的天数一定能满足
问题是我们怎么check 呢?
我们把所有商品能被买的时间都放进被check的时间里面
注意我们要留最大的天 就是要买 我一定是能买的时候最晚买你
买晚剩个没买的个数 都用 2的代价去购买
这样我们check函数就可以check了
然后输出答案即可
/*
if you can't see the repay
Why not just work step by step
rubbish is relaxed
to ljq
*/
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod = (int)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
void exgcd(ll a,ll b,ll &x,ll &y,ll &d){if(!b) {d = a;x = 1;y=0;}else{exgcd(b,a%b,y,x,d);y-=x*(a/b);}}//printf("%lld*a + %lld*b = %lld\n", x, y, d);
/*namespace sgt
{
#define mid ((l+r)>>1)
#undef mid
}*/
const int MAX_N = 200025;
int num[MAX_N],n,num_[MAX_N];
vector<int> vt[MAX_N];
vector<int> day[MAX_N];
bool check(int x,int ck)
{
for(int i = 1;i<=x;++i)
day[i].clear();
for(int i = 1;i<=n;++i)
num_[i] = num[i];
int sum_ = 0;
for(int i = 1;i<=n;++i)
{
int sz = vt[i].size();
if(!sz) continue;
if(vt[i][sz-1]<=x)
{
day[vt[i][sz-1]].push_back(i);
}
else
{
int xb = upper_bound(vt[i].begin(),vt[i].end(),x)-vt[i].begin();
if(xb==0) continue;
else
{
day[vt[i][xb-1]].push_back(i);
}
}
}
int sum = 0;
for(int i = 1;i<=x;++i)
{
sum++;
if(day[i].size())
{
for(int j = 0;j<day[i].size();++j)
{
if(num_[day[i][j]])
{
sum_ += min(sum,num_[day[i][j]]);
sum -= min(sum,num_[day[i][j]]);
}
}
}
}
if(sum>=(ck - sum_)*2) return true;
return false;
}
int main()
{
//ios::sync_with_stdio(false);
//freopen("a.txt","r",stdin);
//freopen("b.txt","w",stdout);
int m,a,b,sum = 0;
scanf("%d%d",&n,&m);
for(int i = 1;i<=n;++i) scanf("%d",&num[i]),sum+=num[i];
while(m--)
{
scanf("%d%d",&a,&b);
vt[b].push_back(a);
}
for(int i = 1;i<=n;++i)
sort(vt[i].begin(),vt[i].end());
int l = 1, r = sum*2;
while(l<=r)
{
int mid = (l+r)/2;
if(check(mid,sum)) r = mid - 1;
else l = mid + 1;
}
printf("%d\n",l);
//fclose(stdin);
//fclose(stdout);
//cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
return 0;
}