这次double精度上卡了,赛时和学校强队差两题
题目链接:https://codeforces.com/gym/104023/problem
A. Dunai
队友写的,答案在总冠军位人数和位置上冠军加非冠军人数最小取min?
#include<bits/stdc++.h>
#define test(i) cout << #i << " "<< i << " " << endl;
#define endl '\n'
using namespace std;
typedef long long ll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
ll t,n;
ll cnt[10];
ll cnt1[10];
map<string,ll> mp;//队伍数量
map<string,ll> vis;
void fio(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main()
{
fio();
ll m,num;
cin >> n;
string str,name;
for(int i=1; i<=n; i++){
for(int j=1; j<=5; j++){
cin >> name;
vis[name]++;
}
}
cin >> m;
for(int i=1; i<=m; i++){
cin >> str >> num;
if(vis[str]) cnt1[num]++;
else cnt[num]++;
}
ll ans=0;
ll tmp=1e9+1;
for(int i=1; i<=5; i++){
ans+=cnt1[i];
tmp=min(cnt1[i]+cnt[i],tmp);
}
cout << min(ans,tmp) << endl;
return 0;
}
E. Python Will be Faster than C++
队友写的
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef char ElemType;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll n, k;
ll a[100];
int main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
if (a[i] < k) {
cout << "Python 3."<<i<<" will be faster than C++"<<endl;
return 0;
}
}
if (a[n] >= a[n - 1]) {
cout << "Python will never be faster than C++"<<endl;
}
else {
if (a[n] == k) {
cout<< "Python 3." << n+1 << " will be faster than C++" << endl;
}
else {
ll ans = (a[n] - k) / (a[n-1] - a[n]) + 1;
cout << "Python 3." << n+ans << " will be faster than C++" << endl;
}
}
}
G. Grade 2
打表得规律
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll x,ll y)
{
if(y==0)
return x;
else
return gcd(y,x%y);
}
map<ll,ll>q;
ll a[2550];
ll g[2500000];
int main()
{
ll x,n;
cin>>x>>n;
ll cnt=0;
ll u=x;
//ll j=*lower_bound(a+1,a+1+cnt,x);
for(ll i=1;i<=31;i++)
{
q[1ll<<i]++;
cnt++;
a[cnt]=1ll<<i;
}
ll j=*lower_bound(a+1,a+1+cnt,x);
for(ll i=1;i<=j;i++)
{
g[i]=0;
}
for(ll i=1;i<=j;i++)
{
g[i]=g[i-1]+(gcd(((i*x)^x),x)==1);
}
x=j-1;
while(n--)
{
ll l,r;
cin>>l>>r;
if(q[u]>0)
{
cout<<0<<endl;
}
else
{
ll u=(l-1)/(x+1);
ll l1=1+u*(x+1);//左边周期
ll k=(r-1)/(x+1);
ll r1=(x+1)+(k)*(x+1);
// cout<<u<<" "<<l1<<" "<<k<<" "<<r1<<endl;
// cout<<g[l-1-l1+1]<<endl;
cout<<(k-u+1)*(g[x+1])-g[l-1-l1+1]-(g[x+1]-g[((x+1)-(r1-r))])<<endl;
}
}
}
I. Dragon Bloodline
优先队列+二分+unsigned long long
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
typedef unsigned long long ll;
ll a[50010];
long long b[30];
ll c[30];
ll n, k;
bool ck(long long x)
{
priority_queue<ll>q;
for (ll i = 1; i <= n; i++)
{
q.push((ll)a[i] * x);
}
while (!q.empty())
{
int ans = 0;
ll op = q.top();
for (ll j = k; j >= 1; j--)
{
if (c[j] > 0)
{
if (op <= b[j])
{
c[j]--;
q.pop();
}
else
{
ll u = op / b[j];
u = min(u, c[j]);
op -= u * b[j];
c[j] -= u;
q.pop();
if (op > 0)
q.push(op);
}
break;
}
else
ans++;
}
if (ans == k)
break;
}
if (q.size() == 0)
{
return 1;
}
else
return 0;
}
ll d[25];
int main()
{
ll t;
cin >> t;
while (t--)
{
cin >> n >> k;
for (ll i = 1; i <= n; i++)cin >> a[i];
for (int i = 1; i <= k; i++)
{
cin >> c[i];
d[i] = c[i];
b[i] = (1ll << (i - 1));
}
long long l = 1, r = 1e18;
while (l <= r)
{
for (ll i = 1; i <= k; i++)c[i] = d[i];
long long mid = (l + r) >> 1;
if (ck(mid))
l = mid + 1;
else
r = mid - 1;
}
cout << r << endl;
}
}
J. Eat, Sleep, Repeat
双端队列模拟
#include<map>
#include<iostream>
#include<set>
#include<deque>
using namespace std;
typedef long long ll;
void fio()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll gcd(ll x, ll y)
{
if (y == 0)
return x;
else
return gcd(y, x % y);
}
map<ll, ll>q, e;
ll a[255000];
ll g[250000];
set<pair<ll, ll>>f;
int main()
{
fio();
ll t;
cin >> t;
while (t--)
{
f.clear();
q.clear();
e.clear();
ll n, m;
cin >> n >> m;
for (ll i = 1; i <= n; i++)
{
cin >> a[i];
q[a[i]]++;
}
for (ll i = 1; i <= m; i++)
{
ll x, y;
cin >> x >> y;
f.insert({ x,y });
e[x]++;
}
for (ll i = 1; i <= n; i++)
{
if (e[a[i]] == 0)
{
e[a[i]]++;
f.insert({ a[i],(1e16 + 1) });
}
}
ll u = -1;
deque<pair<ll, ll>>lo;
if (e[0] == 0)
{
e[0]++;
f.insert({ 0,1e16 + 1 });
}
ll ans = 0;
ll cnt = -99999999999999;
for (auto j : f)
{
if (q[j.first] > j.second)
{
ans = 0;
break;
}
//cout<<j.first<<" "<<j.second<<endl;
cnt++;
if (cnt > 0 && j.first != cnt)
{
lo.push_back({ 1e16 + 5,cnt });
cnt = -9999999999999;
}
if (lo.empty())
{
ll op = j.second - q[j.first];
q[j.first] = 0;
if (op > 0)
{
lo.push_back({ op,j.first });
}
cnt=j.first;
continue;
}
if (j.second != 0)
{
while (!lo.empty())
{
if (lo.front().first >= q[j.first])
{
ll c = lo.front().second;
ll k = lo.front().first - q[j.first];
cnt = j.first;
ans += q[j.first] * (j.first - lo.front().second);
q[j.first] = 0;
lo.pop_front();
if (k != 0)
{
lo.push_front({ k,c });
}
lo.push_back({ j.second,j.first });
break;
}
else
{
ll c = lo.front().second;
ll k = -lo.front().first + q[j.first];
cnt = j.first;
ans += lo.front().first * (j.first - lo.front().second);
q[j.first] = k;
lo.pop_front();
}
if(lo.empty())
{
ll op = j.second - q[j.first];
lo.push_back({ op,j.first });
cnt = j.first;
break;
}
}
}
else
{
lo.clear();
cnt = j.first;
continue;
}
}
//cout << ans << endl;
if (ans % 2 == 0)
{
cout << "FuuFuu" << endl;
}
else
cout << "Pico" << endl;
}
}
标签:2024.10,include,训练,lo,ll,cnt,long,团队,first
From: https://www.cnblogs.com/cjcf/p/18448396