• [计算机网络] 三次握手四次挥手


    问题

    主机A向主机B连续发送了两个TCP报文段,其序号分别是70和100。
    试问:
    (1)第一个报文段携带了多少字节的数据?
    (2)主机B收到第一个报文段后发回的确认中的确认号应当是多少?
    (3)如果B收到第二个报文段后发回的确认中的确认号是180,试问A发送 的第二个报文段中的数据有多少字节?
    (4)如果A发送的第一个报文段丢失了,但第二个报文段到达了B。B在第二 个报文段到达后向A发送确认。试问这个确认号应为多少?

    解析 :

    1. 第一个报文段的数据序号是 70 − 99 70-99 7099,共 30 30 30字节数据

    2. B B B期望收到下一个报文段的第一个数据字节的序号是 100 100 100,则确认号是 100 100 100

    3. 如果第二个报文段中的数据中的字节数是 180 180 180,那么第二个报文段的数据有 180 − 100 = 80 180-100=80 180100=80字节

    4. B在第二个报文段到达后向 A A A发送确认,其确认号为 70 70 70

      凑篇幅

    // Problem: C - ±1 Operation 1
    // Contest: AtCoder - Aising Programming Contest 2022(AtCoder Beginner Contest 255)
    // URL: https://atcoder.jp/contests/abc255/tasks/abc255_c
    // Memory Limit: 1024 MB
    // Time Limit: 2000 ms
    // 
    // Powered by CP Editor (https://cpeditor.org)
    
    #include <iostream>
    #include <vector>
    #include <map>
    #include <cstring>
    #include <queue>
    #include <math.h>
    #include <set>
    #include <stack>
    #include <algorithm>
    using namespace std;
    #define IOS  ios::sync_with_stdio(false);
    #define CIT  cin.tie(0);
    #define COT  cout.tie(0);
    
    #define ll long long
    #define x first
    #define y second
    #define pb push_back
    #define endl '\n'
    #define all(x) (x).begin(),x.end()
    #define Fup(i,a,b) for(int i=a;i<=b;i++)
    #define Fde(i,a,b) for(int i=a;i>=b;i--)
    #define cer(a) cerr<<#a<<'='<<(a)<<" @ line "<<__LINE__<<" "<<endl
    typedef priority_queue<int,vector<int>,greater<int>>  Pri_m;
    typedef pair<int,int> pii;
    typedef vector<int> VI;
    map<int,int> mp;
    const int N = 2e5+10,INF = 0x3f3f3f3f;
    const double eps = 1e-5;
    
    
    struct node{
        int to,val;
    };
    
    
    ll x,a,d,n;
    
    void solve(){
    	cin>>x>>a>>d>>n;
    	
    	ll _an = a + (n-1) * d;
    	
    	if(d < 0 ){
    		swap(_an,a);
    		d = -d;
    	}
    	
    	if(x > _an) cout<<abs(x - _an)<<endl;
    	else if(x < a) cout<<abs(a - x)<<endl;
    	else{
    		if(!d) cout<<0<<endl;
    		else{
    			ll t = (x - a)%d;
    			cout<<min(t,d-t)<<endl;
    		}
    	}
    	
    }
    
    int main(){
        //int t;cin>>t;while(t--)
        solve();
        return 0 ;
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
  • 相关阅读:
    从 0 开始手把手带你搭建一套规范的 Vue3.x 项目工程环境
    flutter 版本更新
    【附源码】计算机毕业设计SSM时间管理系统
    没睡醒就来上班的程序员解决BUG
    SELinux for Android的基本知识和实战
    Semaphore学习
    Npm Install Docusaurus Demo【npm 安装 docusaurus 实践 】
    leetcode 01.08零矩阵
    Mac上安装Java的JDK多版本管理软件jEnv
    clean code-代码整洁之道 阅读笔记(第十二章)
  • 原文地址:https://blog.csdn.net/GzmObject/article/details/125452540