当前位置:网站首页>2022/7/30
2022/7/30
2022-07-31 10:36:00 【killer_queen4804】
D-Jobs (Easy Version)_"蔚来杯"2022牛客暑期多校训练营4 (nowcoder.com)
看了群里大佬的提示,可以预处理出这样的一个数组p[i][j][k]表示iq为i,eq为j在进入第k个公司最低需要多少aq,然后就可以进行o(n)的查询了
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll MAX=1e6+5;
const ll mod=998244353;
ll n,q,p[500][500][20];
ll seed,lastans;
ll fastpow(ll a,ll b)
{
ll res=1;
while(b)
{
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
ll solve(ll iq,ll eq,ll aq){
ll res=0;
for(ll i=1;i<=n;i++){
if(aq>=p[iq][eq][i]) res++;
}
return res;
}
int main(){
for(int i=0;i<=405;i++)
for(int j=0;j<=405;j++)
for(int k=0;k<=15;k++) p[i][j][k]=1e18;
scanf("%lld%lld",&n,&q);
for(int i=1;i<=n;i++){
ll m;scanf("%lld",&m);
for(int j=1;j<=m;j++){
ll x,y,z;
scanf("%lld%lld%lld",&x,&y,&z);
p[x][y][i]=min(p[x][y][i],z);
}
}
for(int k=1;k<=n;k++)
for(int i=1;i<=400;i++)
for(int j=1;j<=400;j++){
p[i][j][k]=min({p[i][j][k],p[i-1][j][k],p[i][j-1][k]});
//cout<<p[i][j][k]<<" "<<i<<" "<<j<<" "<<k<<endl;
}
scanf("%lld",&seed);
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1,400);
ll ans=0;
lastans=0;
for (int i=1;i<=q;i++)
{
int IQ=(u(rng)^lastans)%400+1; // The IQ of the i-th friend
int EQ=(u(rng)^lastans)%400+1; // The EQ of the i-th friend
int AQ=(u(rng)^lastans)%400+1; // The AQ of the i-th friend
//cout<<IQ<<" "<<EQ<<" "<<AQ<<endl;
lastans=solve(IQ,EQ,AQ); // The answer to the i-th friend
ans=(ans+lastans*fastpow(seed,q-i)%mod)%mod;
}
printf("%lld\n",ans);
system("pause");
return 0;
}
1506E - Restoring the Permutation迭代数组
一开始用的双端队列发现根本不是一回事,然后又选择了二分超时了,然后又改成了while虽然多过了两组但还是超时了,最后看题解才知道可以设一个dis数组表示小于i的最大的数是多少,迭代查找的次数很少,可以通过
Codeforces Round #710 (Div. 3) E. Restoring the Permutation_帅气的伯云的博客-CSDN博客
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll MAX=1e6+5;
const ll mod=998244353;
ll t,n,q[200005],visa[200005],visb[200005],mx[200005],mi[200005],vis[200005],dis[200005];
int main(){
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
for(int i=1;i<=n;i++) vis[i]=visa[i]=visb[i]=dis[i]=0;
for(int i=1;i<=n;i++) scanf("%lld",&q[i]);
ll a=n,b=1;
for(int i=1;i<=n;i++){
if(vis[q[i]]){
a=dis[q[i]];
while(visa[a]) a=dis[a];
mx[i]=a;visa[a]=1;dis[q[i]]=a-1;
while(visb[b]) b++;
mi[i]=b;visb[b]=1;
}
else{
mx[i]=mi[i]=q[i];
dis[q[i]]=q[i]-1;
vis[q[i]]=visa[q[i]]=visb[q[i]]=1;
}
}
for(int i=1;i<=n;i++) printf("%lld ",mi[i]);
printf("\n");
for(int i=1;i<=n;i++) printf("%lld ",mx[i]);
printf("\n");
}
system("pause");
return 0;
}
812C - Sagheer and Nubian Market二分
还以为是dp,想了很久没想出来,题解思路是二分,二分找出k,然后贪心找最小花费
codeforce 812C Sagheer and Nubian Market(二分查找)_China震震的博客-CSDN博客
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll MAX=1e6+5;
const ll mod=998244353;
ll n,s,a[100005],b[100005];
bool check(ll x){
for(int i=1;i<=n;i++) b[i]=a[i]+i*x;
sort(b+1,b+n+1);
ll res=0;
for(int i=1;i<=x;i++) res+=b[i];
return res<=s;
}
int main(){
scanf("%lld%lld",&n,&s);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
ll l=1,r=n,res=0,ans=0;
while(l<=r){
ll mid=l+r>>1;
if(check(mid)) res=mid,l=mid+1;
else r=mid-1;
}
for(int i=1;i<=n;i++) b[i]=a[i]+i*res;
sort(b+1,b+n+1);
for(int i=1;i<=res;i++) ans+=b[i];
printf("%lld %lld\n",res,ans);
system("pause");
return 0;
}
K-NIO's Sword_"蔚来杯"2022牛客暑期多校训练营4 (nowcoder.com)
假设走第i步需要k次,那么A[i]=A[i-1]*10^k+xi,xi<10^k,从小到大枚举k,只要x在范围内就说明找到了解,最后步数累加起来输出答案
#include <bits/stdc++.h>
#define ll long long
#define lowbit(x) ((x)&(-x))
using namespace std;
const ll MAX=1e6+5;
const ll mod=998244353;
ll n,ten[15];
ll cal(ll x){
ll res=0;
if(x==1) return 0;
for(int i=1;i<=n;i++){
ll y=i-1;
for(int j=0;j<=10;j++){
ll k=y*ten[j];
k=((i-k)%n+n)%n;
if(k<ten[j]){
res+=j;break;
}
}
}
return res;
}
int main(){
ten[0]=1;
for(int i=1;i<=10;i++) ten[i]=ten[i-1]*10LL;
scanf("%lld",&n);
printf("%lld\n",cal(n));
system("pause");
return 0;
}
边栏推荐
猜你喜欢

C#之泛型、委托、事件及其使用

双链表的插入和删除

SQL study notes - REGEXP operator

Usage of exists in sql
![[Part 1 of Cloud Native Monitoring Series] A detailed explanation of Prometheus monitoring system](/img/af/341c3c3f7e5bcc9172059657c08c4b.png)
[Part 1 of Cloud Native Monitoring Series] A detailed explanation of Prometheus monitoring system

新人学习小熊派华为iot介绍

Emotional crisis, my friend's online dating girlfriend wants to break up with him, ask me what to do

(C language) program environment and preprocessing

Principle of Redis Sentinel

FCN中制作自己的数据集并进行训练
随机推荐
如何判断自己是否适合IT行业?方法很简单
LeetCode二叉树系列——101.对称二叉树
实现弹框组件
【LeetCode】118.杨辉三角
小程序如何使用订阅消息(PHP代码+小程序js代码)
项目管理工具之燃尽图:动态考核团队工作能力
"JUC Concurrent Programming - Advanced" 06 - Immutability of Shared Models (Design of Immutable Classes | Use of Immutable Classes | Flyweight Pattern)
【GORM】存取数组/自定义类型数据
双链表的插入和删除
darknet 训练分类网络
尚医通【预约挂号系统】总结
众多mock工具,这一次我选对了
Mybaits Frequently Asked Questions Explained
7 days to learn Go, Go structure + Go range to learn
SQL去重的三种方法汇总
SQL存储过程详解
Implement the popup component
Can I find a Go job in 7 days?Learn Go with arrays and pointers
怎样使用浏览器静默打印网页
Redis缓存面临的缓存击穿问题