• 2022/7/30


    D-Jobs (Easy Version)_"蔚来杯"2022牛客暑期多校训练营4 (nowcoder.com)

    看了群里大佬的提示,可以预处理出这样的一个数组p[i][j][k]表示iq为i,eq为j在进入第k个公司最低需要多少aq,然后就可以进行o(n)的查询了

    1. #include
    2. #define ll long long
    3. #define lowbit(x) ((x)&(-x))
    4. using namespace std;
    5. const ll MAX=1e6+5;
    6. const ll mod=998244353;
    7. ll n,q,p[500][500][20];
    8. ll seed,lastans;
    9. ll fastpow(ll a,ll b)
    10. {
    11. ll res=1;
    12. while(b)
    13. {
    14. if(b&1) res=res*a%mod;
    15. a=a*a%mod;
    16. b>>=1;
    17. }
    18. return res;
    19. }
    20. ll solve(ll iq,ll eq,ll aq){
    21. ll res=0;
    22. for(ll i=1;i<=n;i++){
    23. if(aq>=p[iq][eq][i]) res++;
    24. }
    25. return res;
    26. }
    27. int main(){
    28. for(int i=0;i<=405;i++)
    29. for(int j=0;j<=405;j++)
    30. for(int k=0;k<=15;k++) p[i][j][k]=1e18;
    31. scanf("%lld%lld",&n,&q);
    32. for(int i=1;i<=n;i++){
    33. ll m;scanf("%lld",&m);
    34. for(int j=1;j<=m;j++){
    35. ll x,y,z;
    36. scanf("%lld%lld%lld",&x,&y,&z);
    37. p[x][y][i]=min(p[x][y][i],z);
    38. }
    39. }
    40. for(int k=1;k<=n;k++)
    41. for(int i=1;i<=400;i++)
    42. for(int j=1;j<=400;j++){
    43. p[i][j][k]=min({p[i][j][k],p[i-1][j][k],p[i][j-1][k]});
    44. //cout<
    45. }
    46. scanf("%lld",&seed);
    47. std::mt19937 rng(seed);
    48. std::uniform_int_distribution<> u(1,400);
    49. ll ans=0;
    50. lastans=0;
    51. for (int i=1;i<=q;i++)
    52. {
    53. int IQ=(u(rng)^lastans)%400+1; // The IQ of the i-th friend
    54. int EQ=(u(rng)^lastans)%400+1; // The EQ of the i-th friend
    55. int AQ=(u(rng)^lastans)%400+1; // The AQ of the i-th friend
    56. //cout<
    57. lastans=solve(IQ,EQ,AQ); // The answer to the i-th friend
    58. ans=(ans+lastans*fastpow(seed,q-i)%mod)%mod;
    59. }
    60. printf("%lld\n",ans);
    61. system("pause");
    62. return 0;
    63. }

    1506E - Restoring the Permutation迭代数组

    一开始用的双端队列发现根本不是一回事,然后又选择了二分超时了,然后又改成了while虽然多过了两组但还是超时了,最后看题解才知道可以设一个dis数组表示小于i的最大的数是多少,迭代查找的次数很少,可以通过

    Codeforces Round #710 (Div. 3) E. Restoring the Permutation_帅气的伯云的博客-CSDN博客

    1. #include
    2. #define ll long long
    3. #define lowbit(x) ((x)&(-x))
    4. using namespace std;
    5. const ll MAX=1e6+5;
    6. const ll mod=998244353;
    7. ll t,n,q[200005],visa[200005],visb[200005],mx[200005],mi[200005],vis[200005],dis[200005];
    8. int main(){
    9. scanf("%lld",&t);
    10. while(t--){
    11. scanf("%lld",&n);
    12. for(int i=1;i<=n;i++) vis[i]=visa[i]=visb[i]=dis[i]=0;
    13. for(int i=1;i<=n;i++) scanf("%lld",&q[i]);
    14. ll a=n,b=1;
    15. for(int i=1;i<=n;i++){
    16. if(vis[q[i]]){
    17. a=dis[q[i]];
    18. while(visa[a]) a=dis[a];
    19. mx[i]=a;visa[a]=1;dis[q[i]]=a-1;
    20. while(visb[b]) b++;
    21. mi[i]=b;visb[b]=1;
    22. }
    23. else{
    24. mx[i]=mi[i]=q[i];
    25. dis[q[i]]=q[i]-1;
    26. vis[q[i]]=visa[q[i]]=visb[q[i]]=1;
    27. }
    28. }
    29. for(int i=1;i<=n;i++) printf("%lld ",mi[i]);
    30. printf("\n");
    31. for(int i=1;i<=n;i++) printf("%lld ",mx[i]);
    32. printf("\n");
    33. }
    34. system("pause");
    35. return 0;
    36. }

    812C - Sagheer and Nubian Market二分

    还以为是dp,想了很久没想出来,题解思路是二分,二分找出k,然后贪心找最小花费

    codeforce 812C Sagheer and Nubian Market(二分查找)_China震震的博客-CSDN博客

    1. #include
    2. #define ll long long
    3. #define lowbit(x) ((x)&(-x))
    4. using namespace std;
    5. const ll MAX=1e6+5;
    6. const ll mod=998244353;
    7. ll n,s,a[100005],b[100005];
    8. bool check(ll x){
    9. for(int i=1;i<=n;i++) b[i]=a[i]+i*x;
    10. sort(b+1,b+n+1);
    11. ll res=0;
    12. for(int i=1;i<=x;i++) res+=b[i];
    13. return res<=s;
    14. }
    15. int main(){
    16. scanf("%lld%lld",&n,&s);
    17. for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    18. ll l=1,r=n,res=0,ans=0;
    19. while(l<=r){
    20. ll mid=l+r>>1;
    21. if(check(mid)) res=mid,l=mid+1;
    22. else r=mid-1;
    23. }
    24. for(int i=1;i<=n;i++) b[i]=a[i]+i*res;
    25. sort(b+1,b+n+1);
    26. for(int i=1;i<=res;i++) ans+=b[i];
    27. printf("%lld %lld\n",res,ans);
    28. system("pause");
    29. return 0;
    30. }

    K-NIO's Sword_"蔚来杯"2022牛客暑期多校训练营4 (nowcoder.com)

    假设走第i步需要k次,那么A[i]=A[i-1]*10^k+xi,xi<10^k,从小到大枚举k,只要x在范围内就说明找到了解,最后步数累加起来输出答案

    出题人第四场_哔哩哔哩_bilibili

    1. #include
    2. #define ll long long
    3. #define lowbit(x) ((x)&(-x))
    4. using namespace std;
    5. const ll MAX=1e6+5;
    6. const ll mod=998244353;
    7. ll n,ten[15];
    8. ll cal(ll x){
    9. ll res=0;
    10. if(x==1) return 0;
    11. for(int i=1;i<=n;i++){
    12. ll y=i-1;
    13. for(int j=0;j<=10;j++){
    14. ll k=y*ten[j];
    15. k=((i-k)%n+n)%n;
    16. if(k
    17. res+=j;break;
    18. }
    19. }
    20. }
    21. return res;
    22. }
    23. int main(){
    24. ten[0]=1;
    25. for(int i=1;i<=10;i++) ten[i]=ten[i-1]*10LL;
    26. scanf("%lld",&n);
    27. printf("%lld\n",cal(n));
    28. system("pause");
    29. return 0;
    30. }

  • 相关阅读:
    详解 SSL(三):SSL 证书该如何选择?
    MyBatis与Spring的整合
    模拟实现字符串函数和内存函数
    【RPC 协议】序列化与反序列化 | lua-cjson | lua-protobuf
    【MySQL】MySQL基础、详细总结
    JavaScript处理数组数据-数据匹配-剔除
    Netty百万级高并发支持
    Hadoop集群搭建--时间同步
    newstarctf2022week2
    【iCloud】土耳其苹果礼品卡购买
  • 原文地址:https://blog.csdn.net/weixin_52621204/article/details/126077686