Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition)

HITS算法详解及代码实现 占坑 阅读详情

A. Little Artem and Matrix

  没什么好说的,逆向模拟一下。

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;

#define ll long long

int a[10010][5];

int ans[111][111];

int main(){
    int n,m,q;
    cin>>n>>m>>q;

    for(int i=1;i<=q;i++){
        scanf("%d",&a[i][0]);
        if(a[i][0]==3){
            for(int j=1;j<=3;j++){
                scanf("%d",&a[i][j]);
            }
        }else{
            scanf("%d",&a[i][1]);

        }
    }

    for(int i=q;i>0;i--){
        if(a[i][0]==1){ 
            int tmp = ans[ a[i][1] ][m];
            for(int j=m;j>1;j--){
                ans[ a[i][1] ][j] = ans[ a[i][1] ][j-1];
            }
            ans[ a[i][1] ][1] = tmp;
        }else if(a[i][0]==2){
            int tmp = ans[ n ][a[i][1]];
            for(int j=n;j>1;j--){
                ans[ j ][a[i][1]] = ans[j-1][ a[i][1] ];
            }
            ans[1][ a[i][1] ] = tmp;
        }else if(a[i][0]==3){
            ans[a[i][1]][a[i][2]] = a[i][3];
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cout<<ans[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

B. Little Artem and Dance

  其实分析一下就能发现,奇数的相对位置是不会变的,偶数的也是。所以一个简单的做法就是维护1和2的位置。

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;

#define ll long long

int ans[1000010];

int main(){
    int n,q;
    cin>>n>>q;

    int one = 1;
    int two = 2;

    for(int i=1;i<=q;i++){
        int op;
        scanf("%d",&op);
        if(op==1){
            int x;
            scanf("%d",&x);
            one+=x;
            two+=x;
        }else{
            if(one&1){
                one++;
            }else{
                one--;
            }
            if(two&1){
                two++;
            }else{
                two--;
            }
        }
        while(one>n){
            one-=n;
        }
        while(one<1){
            one+=n;
        }
        while(two>n){
            two-=n;
        }
        while(two<1){
            two+=n;
        }
    }

    for(int i=1;i<=n;i+=2){
        ans[one]=i;
        one+=2;
        if(one>n){
            one-=n;
        }
    }

    for(int i=2;i<=n;i+=2){
        ans[two]=i;
        two+=2;
        if(two>n){
            two-=n;
        }
    }

    for(int i=1;i<=n;i++){
        printf("%d ",ans[i]);
    }

    return 0;
}

C. Little Artem and Random Variable

  大坑!C居然比D难,差一点码完,巨亏。。
  我们按顺序推两个骰子的每个点的概率即可。根据max和min的分布,可以推出一个一元二次方程,化简然后解之可以得到每个点的概率。。
  这个题我跪了一发,跪在二次方程判别式出现了一个极小的负数。。

#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;

#define ll long long


double ansA[100010];
double ansB[100010];


double delta;
double x1,x2;

// ax^2 + bx + c = 0
void solve(double a,double b,double c){
    double d=b*b-4*a*c; 
    delta = d;

    if(d<=0){ 
        x1=x2=(-b)/(2*a); 
    }else{
        double e=sqrt(d); 
        x1=(-b+e)/(2*a); 
        x2=(-b-e)/(2*a); 
    } 
}

double MIN[100010];
double MAX[100010];

int main(){
    int n;
    cin>>n;

    for(int i=1;i<=n;i++){
        scanf("%lf",&MAX[i]);
    }

    for(int i=1;i<=n;i++){
        scanf("%lf",&MIN[i]);
    }

    double suma=0;
    double sumb=0;
    for(int i=1;i<=n;i++){
        // ansA[i] + ansB[i] = MIN[i] + MAX[i]
        // sumb*ansA[i] +suma*ansB[i] + ansA[i]*ansB[i] = MAX[i]
        // 
        double minSum = min(suma,sumb);
        // let x = ansA[i]

        double sum = MIN[i] + MAX[i];

        double a = -1.0;
        double b = sumb - suma + sum;
        double c = suma*sum - MAX[i] ;

        solve(a,b,c);

        x2 = sum-x1;
        ansA[i] = x1;
        ansB[i] = x2;

        suma += x1;
        sumb += x2;
    }

    for(int i=1;i<=n;i++){
        cout<<ansA[i]<<" ";
    }
    cout<<endl;
    for(int i=1;i<=n;i++){
        cout<<ansB[i]<<" ";
    }

    return 0;
}

D. Little Artem and Time Machine

  又是喜闻乐见的数据结构题。。这个题并不需要什么高端的姿势,大家常见的数据结构就能解决。首先,对不同的数的操作其实是独立的,可以分开处理。对于每个操作数,把操作时间离散化,用BIT维护对它进行增加,删除的时间,再根据查询操作的时间点查询一下在这之前被增加/删除了多少次,增加次数减去删除次数就是答案。。

#include <bits/stdc++.h>

using namespace std;

struct operation{
    int op;
    int time;
    int x;
    int id;
    bool operator<(const operation &other)const{
        if(x!=other.x){
            return x<other.x;
        }
        return id<other.id;
    }
}ops[100010];

int ca[100010];
int cr[100010];

int lowbit(int x){
    return x&(-x);
}

int sz;
void updatea(int x){
    while(x<=sz){
        ca[x]++;
        x+=lowbit(x);
    }
}

int querya(int x){
    int res = 0;
    while(x){
        res+=ca[x];
        x-=lowbit(x);
    }
    return res;
}

void updater(int x){
    while(x<=sz){
        cr[x]++;
        x+=lowbit(x);
    }
}

int queryr(int x){
    int res = 0;
    while(x){
        res+=cr[x];
        x-=lowbit(x);
    }
    return res;
}

int res[100010];

int main(){
    memset(res,-1,sizeof(res));
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&ops[i].op,&ops[i].time,&ops[i].x);
        ops[i].id = i;
    }
    sort(ops,ops+n);

    for(int i=0;i<n;i++){
        int end = i;
        while(ops[end].x==ops[end+1].x && end<n-1){
            end++;  
        }

        map<int,int> mp;
        for(int j=i;j<=end;j++){
            mp[ops[j].time];
        }

        int k = 1;

        for(auto it = mp.begin();it!=mp.end();it++){
            it->second = k++;
        }

        sz = end-i+2;
        for(int j=0;j<=sz;j++){
            ca[j] = cr[j] = 0;
        }
        for(int j=i;j<=end;j++){
            int mpTime = mp[ops[j].time];
            if(ops[j].op==1){
                updatea(mpTime);
            }else if(ops[j].op==2){
                updater(mpTime);
            }else{
                int ans = querya(mpTime) - queryr(mpTime);
                res[ops[j].id] = ans;
            }
        }
        i = end;
    }


    for(int i=0;i<n;i++){
        if(res[i]!=-1){
            printf("%d\n",res[i]);
        }
    }
    return 0;
}
回归预测 | MATLAB实现MPR多元多项式回归 阅读详情

相关推荐

用SOEM库搞定汇川SV660N伺服电机:一个Linux C程序员的EtherCAT实战笔记

本文详细介绍了如何在Linux系统下使用SOEM库驱动汇川SV660N伺服电机,包括环境搭建、EtherCAT从站设备识别、PDO映射配置、状态机切换与运动控制等关键步骤。通过实战代码示例和常见问题排查指南,帮助开发者快速掌握工业自动化中的EtherCAT通信技术,实现对伺服电机的精准控制。

weixin_29185199的博客 424

Codeforces Round #471 (Div. 2)

比赛链接 QAQ终于补完了这场的题。。感觉后面几题还都挺好的就写个(非常)简略的总结叭。 A. Feed the cat 简单贪心+模拟。 #include&lt;bits/stdc++.h&gt; #define rep(i,x,y) for (int i=(x); i&lt;=(y); i++) #define ll long long using namespace std;...

juruo? juruo! 674

关于自制的《航空学报》latex模板(非官网模板)

《航空学报》的官网只提供了word模板,并且该期刊投稿只需要pdf版本不需要源文件。为方便latex爱好者撰写论文,提供该模板及说明给广大科研人士~

qq_37105055的博客 4691

Codeforces Round #471 (Div. 2) C. Sad powers

C. Sad powers time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You're givenQqueries of the form(L, R). For ...

Lily1221的博客 265

高通SA8155P车载Camera开发避坑指南:从硬件拓扑到AIS服务调试全流程

本文详细解析了高通SA8155P车载Camera开发全流程,从硬件拓扑设计到AIS(Automotive Imaging System)服务调试,涵盖关键组件配置、软件架构剖析及高级调试技巧。通过实战经验分享,帮助开发者避开常见陷阱,优化系统性能,适用于智能驾驶系统的环境感知开发。

weixin_42550597的博客 331

【GPIO模拟串口通信协议】

由于这段时间搞了个安卓相关的项目,需要和安卓进行Uart通信。但是选用的芯片并没有自带uart功能,所以在充分评估项目后,考虑波特率不高的情况下,决定使用GPIO去模拟串口通信协议了。

学海无涯苦作舟 2638

Codeforces Round #471 (Div. 2) C. Sad powers

题目链接 题意:问区间[L, R]中有多少数字可以写成的形式; 思路::当p&gt;=3时,x&lt;=1e6;只有p=2时x能达到1e9;但是[L, R]区间中满足的数有(int)sqrt(R)-(int)sqrt(L-1)个,所以对于区间[L, R]先找出p&gt;=3的情况,再加上(int)sqrt(R)-(int)sqrt(L-1),而对于p&gt;=3的情况打表找出来就可以了,然后排...

Sirius_han的博客 478

STM32F407通过SMBus协议精准读取BQ40Z50电池电量

本文详细介绍了STM32F407通过SMBus协议精准读取BQ40Z50电池电量的实现方法。从硬件连接到软件驱动开发,再到通信异常排查,提供了完整的解决方案。重点解析了SMBus协议的特殊时序要求、GPIO模拟驱动的关键代码,以及实际调试中的常见问题与对策,帮助开发者高效完成电池管理系统开发。

weixin_29189003的博客 251

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C 离散化+树状数组+map D 数学

链接:戳这里 C. Little Artem and Random Variable time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Little Artyom decided to study probab

Cross 566

Simulink模块库介绍(一)——信号源模块

Simulink模块库介绍(一)——信号源模块库目录Clock模块Digital Clock模块Band-Limited White Noise模块 目录 simulink模块库中提供了丰富的信号源模块组。逐一介绍,算是对之前做个总结吧 Clock模块 通过时钟模块,输出的时间作为判断呢,如下图,前2s之前为高斯白噪声,后2s为正弦曲线,共计10s。 Digital Clock模块 数字时钟模块主要用于离散系统的计时,sample time表示采用时间,如下图:分别是1s和0.5s的采样时间 Band-

5万+

斯坦福大学3D点云模型下载

本文整理了斯坦福大学10个经典的点云(pcd)及其模型(ply),方便日后使用,欢迎免费下载!

孙悟空 7733

[2-SAT] Codeforces 668E #348 (VK Cup 2016 Round 2, Div. 1 Edition) E. Little Artem and 2-SAT

题解   Let’s build for both 2-SAT formulas implication graph and let’s find strong connected components in this graph. If both of the formulas are not satisfiable then the answer is SIMILAR. If only on

雯舞 744

【使用FPGA实现MIPI DSI接口】——如何使用FPGA实现MIPI DSI接口?这是一个让许多开发者都感到困扰的问题。本文将介绍如何使用FPGA设计和实现...

【使用FPGA实现MIPI DSI接口】——如何使用FPGA实现MIPI DSI接口?MIPI DSI(移动产业处理器接口 - 显示串行接口)是一种用于在移动设备中传输视频数据的标准接口,它是目前大部分智能手机和平板电脑所采用的显示接口。首先,我们需要实现MIPI DSI的物理层接口。在实现MIPI DSI接口后,我们还需要编写驱动程序来控制MIPI DSI显示屏显示图像。这里只是提供了MIPI DSI接口的物理层代码示例,完整的MIPI DSI接口实现需要包括控制器和驱动程序等更多内容。

uote_e的博客 1995

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 1 Edition) C. Little Artem and Random Variable 数学...

C. Little Artem and Random Variable 题目连接: http://www.codeforces.com/contest/668/problem/C Description Little Artyom decided to study probability theory. He found a book with a lot of nice exercises an...

weixin_30381793的博客 96

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

STM32F407中文手册

STM32f407中文手册 本参考手册面向应用开发人员,提供有关使用 STM32F405xx/07xx、STM32F415xx/17xx、 STM32F42xxx 和 STM32F43xxx 微控制器存储器与外设的完整信息。STM32F405xx/07xx、STM32F415xx/17xx、STM32F42xxx 和 STM32F43xxx 构成一个微 控制器系列,各产品具有不同的存储器大小、封装和外设。有关订购信息以及器件的机械与电气特性,请参见数据手册。有关 ARM Cortex™-M4F 内核的信息,请参见《Cortex™-M4F 技术参考手册》。

Codeforces VK Cup 2016 - Round 1 (Div. 2 Edition)

A. Bear and Reverse Radewoosh  按要求计算一下即可。#include <bits/stdc++.h>#define ll long longusing namespace std;int p[111]; int t[111];int main(){ int n,c; cin>>n>>c; for(int i=1;i<=n;i++){

A Cube Master 2万+

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

链接:http://codeforces.com/contest/673 problemA. Bear and Game:看90分钟电视,有n个有趣点,如果持续15没有看到有趣的点,那么就关电视,问什么时候会关掉电视。 分析:水题。找到第一个跨度大于15的点即可,注意答案最大90。 代码: #include #include #include #include #include #incl

Fsss 888

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition) ABCD

传送门:http://codeforces.com/contest/673 A: #include using namespace std; typedef __int64 ll; const int INF=0x3f3f3f3f; const int maxn=200005; int T,n,m; int a[maxn]; int main(){ while(~scanf("

To be excellent! 431

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition)-A. Little Artem and Presents(模拟)

A. Little Artem and Presents time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little Artem got n stones on h

梧桐下的四叶草 3792

【解题报告】Codeforces Round #351 (VK Cup 2016 Round 3, Div. 2 Edition)

简略的解题报告。

TRiddle的博客 535

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition)

A. Bear and Colors  模拟一下就完了。#include <bits/stdc++.h>using namespace std;#define ll long long int a[5010]; int cnt[5010]; int ans[5010];int main(){ int n; cin>>n; for(int i=1;i<=n;i++){

A Cube Master 496

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) A B C D 模拟

链接:戳这里 A. Little Artem and Presents time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Little Artem got n stones on his birthday and

Cross 88万+

Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) E. Little Artem and Time Machine 树状数组

题意 有三个操作 1 x y,在第x秒插入一个y 2 x y,在第x秒移走一个y 3 x y, 问第x秒有多少个y 题解: 裸的可持久化treap,可以直接莽一波…… 但是这道题可以用树状数组做,时间复杂度是nlog(1e9)log(1e9)的 所以感觉还是蛮快的 空间是nlogn的 #include #include #include

Ezereal的博客 508

Codeforces Round #351 (VK Cup 2016 Round 3, Div. 1 Edition) C E (斜率优化. 概率)

Levels and Regions 题意:有n个等级,要分成k组,求游戏结束的最小期望。游戏中对于一组等级ai,通过这个等级的概率为ai/sumi,blablabla。。。。 #include #include #include #include #include #include #include #include #include #include

To_c_t_w 493

CodeForces-VK Cup 2012 Round 2 (Unofficial Div. 2 Edition) -C. Substring and Subsequence

"好久不打codeforces了,本来就极菜!还没感觉!特么被生虐有木有! 这题当div2就出20+,div1早早就500+了,差距啊差距. 吐槽:acm的王道在于可持续装逼,其保证来源于可持续的切题!" 一.题目大意:让你求有多少对pair(x,y),其中x来源于字符串s的"连续子串",y则来源于t字符串的"子序集" 二.被虐原因:当时动规主要纠结于这个"子序集"y如何生成,一直未果,蛋

流水不争先 1109
上一篇: TopCoder SRM 688
下一篇: zoj 2342 Roads
squee_spoon
博客等级 码龄14年 61粉丝 455原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值