(CQUPT 的某数据结构homework)

CQUPT 的某数据结构homework

  • 基于线性表的图书信息管理
    • 基于栈的算术表达式求值
    • 基于字符串模式匹配算法的病毒感染检测问题
  • 基于哈夫曼树的数据压缩算法
  • 基于二叉树的表达式求值算法
  • 基于 Dijsktra 算法的最短路
  • 基于广度优先搜索的六度空间
  • 排序算法的实现与分析

基于线性表的图书信息管理

首先,因为我们要输入输出汉语,所以需要更改编码成为utf-8
我使用的是devcpp
所以其他版本编译器更改编码的就请自己去查询更改方式。
工具:
编译选项:
编译时加入以下命令,打勾,下面粘上此代码
-std=c++11 -finput-charset=utf-8

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
struct node_book
{
    string name_book;
    string  id_book;
    float price_book;
    //int myid;

};
unordered_map<string ,int>mmp;//去重用
list<node_book>  books;
vector<node_book>  high_books;
double evrage;
int books_num,idx;
void output(){
    for(auto j:books){
        cout<<j.id_book<<" "<<j.name_book<<" ";
        printf("%.2f\n",j.price_book);
    }
}
void add(string id,float price, string name){
    node_book new_book;
    new_book.id_book = id;
    new_book.name_book = name;
    new_book.price_book = price;
    books.push_back(new_book);
    books_num++;
    evrage+= price;
}
void init(){
    books_num = 0;
    float price;
    string name,id;
    while(1){
        cin>>id>>name>>price;
        if(id=="0"&&name=="0"&&price==0)break;
        add(id,price,name);
        mmp[id]++;
       // evrage += price;
    }
}
void func1(){
    init();
    cout<<books_num<<endl;
    output();
}
void func2(){
    init();
    evrage /= books_num;
    for(auto& j:books){
        float te = j.price_book;
        if(te < evrage)  j.price_book*=1.2;
        else   j.price_book*=1.1;
        
    }
    printf("%.2f\n",evrage);
    cout<<books_num<<endl;
    output();
}
void func3(){
    init();
    high_books.clear();
    high_books.push_back(*books.begin());
    float high_price = high_books[0].price_book;
    for(auto j:books){
        if(j.price_book>high_price){
            high_books.clear();
            high_books.push_back(j);
            high_price = j.price_book;

        }
        else if(high_price==j.price_book){
            high_books.push_back(j);
        }
    }
    cout<<high_books.size()<<endl;
    for(auto j: high_books){
        cout<<j.id_book<<" "<<j.name_book<<" ";
        printf("%.02f\n",j.price_book);
    }
}
void func4(){
    init();
    float price;
    string name,id;
    int place,idx = 1;
    cin>>place;
    cin>>id>>name>>price;
    node_book new_book;
    new_book.id_book = id;
    new_book.name_book = name;
    new_book.price_book = price;
    list<node_book>::iterator pos ;
    pos = books.begin();
    for(auto j:books){
        idx++;
        pos++;
        if(idx==place){
        books.insert(pos,new_book);
        books_num++;
    	cout<<books_num<<endl;
    	output();
    	return;
        }
    }
    cout<<"抱歉,入库位置非法!\n";
    
}
void func5(){
    init();
    float price;
    string name,id;
    int place,idx = 1;
    cin>>place;
    list<node_book>::iterator pos ;
    pos = books.begin();
    for(auto j:books){
        idx++;
        pos++;
        if(idx==place){
        books.erase(pos);
        books_num--;
        }
    }
    cout<<books_num<<endl;
    output();
}
void func6(){
    init();
    int place;
    list<node_book>::iterator pos ;
    vector<list<node_book>::iterator> dela;
    pos = books.begin();
    for(auto j:books){
        //cout<<mmp[j.id_book]<<endl;
        if(mmp[j.id_book]>1){
            mmp[j.id_book]--;
            dela.push_back(pos);
            books_num--;
        }
        pos++;
    }
    for(auto it:dela){
        books.erase(it);
    }
    cout<<books_num<<endl;
    output();
}
void tishi(){
   printf("\n输入1测试:基于顺序(链式)存储结构的图书信息表的创建和输出\n");
   cout<<"输入2测试:基于顺序(链式)存储结构的图书信息表的修改\n";
   cout<<"输入3测试:基于顺序(链式)存储结构的图书信息表的最贵图书的查找\n";
   cout<<"输入4测试:基于顺序(链式)存储结构的图书信息表的新图书的入库\n";
   cout<<"输入5测试:基于顺序(链式)存储结构的图书信息表的旧图书的出库\n";
   cout<<"输入6测试:基于顺序(链式)存储结构的图书信息表的图书去重\n";
   cout<<"输入-1,退出程序\n";
}
int main(){
    int op =1;
    while(op!=0){
    tishi();
    cin>>op;
    if(op== 1)
    func1();
    else if(op==2)
    func2();
    else if(op==3)
     func3();
    else if(op==4)
    func4();
    else if(op==5)
    func5();
    else if(op==6)
    func6();
    
    books.clear();
    
    }
    return 0;
}

基于栈的算术表达式求值

普通应用即可

#include<bits/stdc++.h>
using namespace std;
#define MAXSIZE 100
#define N 10
string S;
//运算符栈 
unordered_map<char,int>mmp;
void init0(){
    mmp['('] = mmp[')']=3;
    mmp['*'] = mmp['/'] = 2;
    mmp['+'] = mmp['-'] = 1;
}

stack<char> sta_op;
stack<int> sta_num;
int verify(char ch)
{
    //cout<<ch<<endl;
    if(ch=='+')
        return 0;
    else if(ch=='-')
        return 1;
    else if(ch=='*')
        return 2;
    else if(ch=='/')
        return 3;
    else if(ch=='(')
        return 4;
    else if(ch==')')
        return 5;
    else
    {
        return 100;
    }
        
}
void push_num(int& idx){
            int j = idx;
            int temp = 0;
            while(S[j]>='0'&&S[j]<='9'){
                temp*=10;
                temp+=S[j]-'0';
                j++;
            }
            sta_num.push(temp);
            idx = j-1;
}
int judge(int a,char e,int b)
{
    //cout<<e<<endl;
    if(e=='+')
        return a+b;
    else if(e=='-')
        return a-b;
    else if(e=='*')
        return a*b;
    else if(e=='/')
        return a/b;
    else
    {
        cout<<"error!"<<endl;
        return -1;
    }
        
}
void func1(int& idx){
    char ch = S[idx];
    if(ch=='('||ch=='+'||ch=='-')
     sta_op.push(ch);//of course +-不需要考虑运算顺序
    else if(ch == '*'||ch=='/'){
        if(S[idx+1]>='0'&&S[idx+1]<='9'){
            //*/在后面跟上的是数字的情况下,一定是可以直接进行运算的
            //那么不妨在这种情况下面直接开算
            int j = idx+1;
            int temp = 0;
            while(S[j]>='0'&&S[j]<='9'){
                temp*=10;
                temp+=S[j]-'0';
                j++;
            }
            sta_num.push(temp);
            idx = j-1;

            //

            int la = sta_num.top();
            sta_num.pop();
            int pre = sta_num.top();
            sta_num.pop();
            int ans = judge(pre,ch,la);
            sta_num.push(ans);
        }
        else{
            sta_op.push(ch);//只能等后面在来运算辣
            //就是等下一个左括号运算完成并出栈的时候来运算此符号
        }
    }else if(ch==')'){
        while(sta_op.top()!='('){
            int la = sta_num.top();
            sta_num.pop();
            int pre = sta_num.top();
            sta_num.pop();
            int ans = judge(pre,sta_op.top(),la);
            sta_op.pop();
            sta_num.push(ans);
        }
        sta_op.pop();
        if(sta_op.top()=='*'||sta_op.top()=='/'){//
        //这个时候就要运算89行处的*/法辣
            int la = sta_num.top();
            sta_num.pop();
            int pre = sta_num.top();
            sta_num.pop();
            int ans = judge(pre,sta_op.top(),la);
            sta_op.pop();
            sta_num.push(ans);
        }
    }

}
int func(){
    cin>>S;
    if(S=="=")return 0;
    for(int i=0;S[i]!='\0';i++)
    {
        if(S[i]>='0'&&S[i]<='9')
            push_num(i);
        else
            func1(i);
     }
     //*/法已经算完辣,+-法没有顺序可言,但是为了减少代码量就不优化辣。
     while(!sta_op.empty()){
            int la = sta_num.top();
            sta_num.pop();
            int pre = sta_num.top();
            sta_num.pop();
            int ans = judge(pre,sta_op.top(),la);
            sta_op.pop();
            sta_num.push(ans);
     } 
    cout<<sta_num.top()<<endl;
    sta_num.pop();
    return 1;
}
int main()
{
    int ti=1;
    while(ti){
        cout<<"\n请输入中缀表达式的算数表达式\n仅输入一个 = 时结束程序\n";
        if(!func())break;

    }
    return 0;
}

基于字符串模式匹配算法的病毒感染检测问题

kmp即可

#include<bits/stdc++.h>
using namespace std;
#define ll long long

typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int N = 1e5 + 10, M = 1e6 + 10;
char p[N], s[M];
int n, m;
int ne[N];

void tishi(){
    cout<<"请输入病毒的ONA序列和人的NDNA序列,用空格隔开\n";
    cout<<"当输入的两个DNA序列为 0 0 时退出程序!\n";
}
bool solve(){
    string x,y;
    cin>>x>>y;
    n = y.size();
    m = x.size();
    if0(n){
        s[i+1]= y[i];
    }
    if0(m) p[i+1] = x[i];
    if(x=="0"&&y=="0")return 0;

    memset(ne,0,sizeof(ne));
    for (int i = 2, j = 0; i <= m; i ++ ){
    while (j && p[i] != p[j + 1]) j = ne[j];
    if (p[i] == p[j + 1]) j ++ ;
    ne[i] = j;
}

// 匹配
for (int i = 0, j = -1; i <= n; i ++ ){
    while (j && s[i] != p[j + 1]) j = ne[j];
    if (s[i] == p[j + 1]) j ++ ;
    if(j==m){
        cout<<"YES\n";
        return 1;
    }
    if (j == m)
    {
        j = ne[j];
        // 匹配成功后的逻辑
    }
}
cout<<"NO\n";
return 1;

}
int main(){
    int t=1;
    while (t)
    {
        tishi();
        if(!solve()) {
            break;
        }
        
    }
   // getchar();
    
    return 0;
}

基于哈夫曼树的数据压缩算法

这个还是比较有趣,可以自己试试

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long

typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
string s;
string ans[1000];
unordered_map<char,int> mmp;
vector<tuple<int,int,int,int>>tre;//重,fa,l,r
bool cmp(pair<char,int> a,pair<char,int> b)
{
    return a.first>b.first;
}
void dfs(int x,string temp){
        if(temp!="\0")
        ans[x] =temp ;
        int w1,w2,f1,f2,l1,l2,r1,r2,id1,id2;
        auto te1 = tre[x];
        tie(w1,f1,l1,r1) = te1;
        if(l1!=-1)dfs(l1,temp+'0');
        if(r1!=-1)dfs(r1,temp+'1');
    
}
void solve(){
    int m,n,idx = 0;
    tre.clear();
    memset(ans,'\0',sizeof(ans));
    priority_queue<pi,vector<pi>,greater<pi>>mq;
    mmp.clear();
    for(auto j:s)mmp[j]++;
    vector<pair<int,int> > ss;
    for(auto j:mmp){
        ss.push_back({j.first,j.second});
    }
    sort(ss.begin(),ss.end());


    for(auto j:ss){
        char ch = j.first;
        printf("%c:%d ",ch,j.second);
        mq.push({j.second,idx++});
        //建树
        tre.push_back({j.second,-1,-1,-1});
    }
    cout<<endl;
    //建立合成节点的树
    while(mq.size()>1){
        auto t1 = mq.top();mq.pop();
        auto t2 = mq.top();mq.pop();
        int w1,w2,f1,f2,l1,l2,r1,r2,id1,id2;
        tie(w1,id1) = t1;tie(w2,id2)  =t2;
        mq.push({w1+w2,idx++});
        tre.push_back({w1+w2,-1,id1,id2});
        //以后要牢记tuple一般用于无修改的操作
        //不是说内容一旦过长就用tuple;
        auto te1 = tre[id1],te2 = tre[id2];
        tie(w1,f1,l1,r1) = te1;
        tie(w2,f2,l2,r2) = te2;
        tre[id1] = {w1,idx-1,l1,r1};
        tre[id2] = {w2,idx-1,l2,r2};

    }

    //输出树
    jf0(idx){
        int w1,w2,f1,f2,l1,l2,r1,r2,id1,id2;
        auto te1 = tre[j];
        tie(w1,f1,l1,r1) = te1;
        cout<<j+1<<" "<<w1<<" "<<f1+1<<" "<<l1+1<<" "<<r1+1<<endl;
    }

    //dfs编码树
    dfs(idx-1,"\0");
    if0(ss.size()){
        char ch = ss[i].first;
        cout<<ch<<":"<<ans[i]<<" ";
    }
    cout<<endl;
    string res;
    if0(ss.size()){
        jf0(ss[i].second){
            res+=ans[i];
        }
    }
    cout<<res<<endl;

    //解码,感觉会比较复杂
   //奥!,dfs编码,那么我也应该是dfs解码,聪明like me
   int now = idx-1;
   for(auto j:res){
        int w1,w2,f1,f2,l1,l2,r1,r2,id1,id2;
        auto te1 = tre[now];
        tie(w1,f1,l1,r1) = te1;
        if(l1==-1){//走到尽头辣,我们就可以输出当前节点的val,并且回溯到根节点
        char ch = ss[now].first;
            cout<<ch;now = idx-1;
            auto te1 = tre[now];
            tie(w1,f1,l1,r1) = te1;
        }
    if(j=='0'){
        //向左边走、
        now = l1;
    }
    else now = r1;
   }
    char ch = ss[now].first;
    cout<<ch;now = idx-1;
    cout<<endl;
}
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr); 
    
    while (1)
    {
        cin>>s;
        if(s=="0")break;
        solve();
    }
   // getchar();
    
    return 0;
}```

## 如何改变文本的样式

*强调文本* _强调文本_

**加粗文本** __加粗文本__

==标记文本==

~~删除文本~~

> 引用文本

H~2~O is是液体。

2^10^ 运算结果是 1024.

## 插入链接与图片

链接: [link](https://www.csdn.net/).

图片: ![Alt](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw)

带尺寸的图片: ![Alt](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw =30x30)

居中的图片: ![Alt](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw#pic_center)

居中并且带尺寸的图片: ![Alt](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9hdmF0YXIuY3Nkbi5uZXQvNy83L0IvMV9yYWxmX2h4MTYzY29tLmpwZw#pic_center =30x30)

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

## 如何插入一段漂亮的代码片

去[博客设置](https://mp.csdn.net/console/configBlog)页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 `代码片`.
```javascript
// An highlighted block
var foo = 'bar';

基于二叉树的表达式求值算法

最傻逼的作业

#include<bits/stdc++.h>
using namespace std;
#define MAXSIZE 100
#define N 10
string S;
//运算符栈 
unordered_map<char,int>mmp;
void init0(){
    mmp['('] = mmp[')']=3;
    mmp['*'] = mmp['/'] = 2;
    mmp['+'] = mmp['-'] = 1;
}
struct node{
    bool isnum;
    int val;
    char op;
    node* L;
    node* R;
};
stack<char> sta_op;
stack<node*> sta_num;
int verify(char ch)
{
    //cout<<ch<<endl;
    if(ch=='+')
        return 0;
    else if(ch=='-')
        return 1;
    else if(ch=='*')
        return 2;
    else if(ch=='/')
        return 3;
    else if(ch=='(')
        return 4;
    else if(ch==')')
        return 5;
    else
    {
        return 100;
    }
        
}
void push_num(int& idx){
            int j = idx;
            int temp = 0;
            while(S[j]>='0'&&S[j]<='9'){
                temp*=10;
                temp+=S[j]-'0';
                j++;
            }
            node* te = new(node);
            te->isnum=1;
            te->val=temp;
            sta_num.push(te);
            idx = j-1;
}
int judge(int a,char e,int b)
{
    //cout<<e<<endl;
    if(e=='+')
        return a+b;
    else if(e=='-')
        return a-b;
    else if(e=='*')
        return a*b;
    else if(e=='/')
        return a/b;
    else
    {
        cout<<"error!"<<endl;
        return -1;
    }
        
}
void func1(int& idx){
    char ch = S[idx];
    if(ch=='('||ch=='+'||ch=='-')
     sta_op.push(ch);//of course +-不需要考虑运算顺序
    else if(ch == '*'||ch=='/'){
        if(S[idx+1]>='0'&&S[idx+1]<='9'){
            //*/在后面跟上的是数字的情况下,一定是可以直接进行运算的
            //那么不妨在这种情况下面直接开算
            int j = idx+1;
            int temp = 0;
            while(S[j]>='0'&&S[j]<='9'){
                temp*=10;
                temp+=S[j]-'0';
                j++;
            }
            node* te = new(node);
            te->isnum=1;
            te->val=temp;
            sta_num.push(te);
            idx = j-1;

            //

            node* re = sta_num.top();
            sta_num.pop();
            node* la = sta_num.top();
            sta_num.pop();
            node* fa =new(node);
            fa->isnum=0;
            fa->op = ch;
            fa->L=la;
            fa->R = re;
            sta_num.push(fa);
        }
        else{
            sta_op.push(ch);//只能等后面在来运算辣
            //就是等下一个左括号运算完成并出栈的时候来运算此符号
        }
    }else if(ch==')'){
        while(sta_op.top()!='('){
            node* re = sta_num.top();
            sta_num.pop();
            node* la = sta_num.top();
            sta_num.pop();
            node* fa =new(node);
            fa->isnum=0;
            fa->op = sta_op.top();
            fa->L=la;
            fa->R = re;
            sta_num.push(fa);
            sta_op.pop();
        }
        sta_op.pop();
        if(sta_op.top()=='*'||sta_op.top()=='/'){//
        //这个时候就要运算109行处的*/法辣
            node* re = sta_num.top();
            sta_num.pop();
            node* la = sta_num.top();
            sta_num.pop();
            node* fa =new(node);
            fa->isnum=0;
            fa->op = sta_op.top();
            fa->L=la;
            fa->R = re;
            sta_num.push(fa);
            sta_op.pop();
        }
    }

}
int dfs(node* root){
    if(root->isnum) return root->val;
    int l = dfs(root->L),r=dfs(root->R);
     return judge(l,root->op,r);
}
int func(){
    cin>>S;
    if(S=="=")return 0;
    for(int i=0;S[i]!='\0';i++)
    {
        if(S[i]>='0'&&S[i]<='9')
            push_num(i);
        else
            func1(i);
     }
     //*/法已经算完辣,+-法没有顺序可言,但是为了减少代码量就不优化辣。
     while(!sta_op.empty()){
            node* re = sta_num.top();
            sta_num.pop();
            node* la = sta_num.top();
            sta_num.pop();
            node* fa =new(node);
            fa->isnum=0;
            fa->op = sta_op.top();
            fa->L=la;
            fa->R = re;
            sta_num.push(fa);
            sta_op.pop();
     } 
    node* root = sta_num.top();
    cout<<dfs(root)<<endl;
    sta_num.pop();
    return 1;
}
int main()
{
    int ti=1;
    while(ti){
        cout<<"\n请输入中缀表达式的算数表达式\n仅输入一个 = 时结束程序\n";
        if(!func())break;

    }
    return 0;
}

基于 Dijsktra 算法的最短路

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long

typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int e[200],h[200],ne[200],w[200],idx,idx1;
unordered_map<string ,int> mmp;
string xiufu[200];
int dist[200];
int pre[200];
int m,n,c;
void add(int a,int b,int c){
    e[idx] = b;
    w[idx] = c;
    ne[idx] = h[a];
    h[a] = idx++;

}

void dijsktra(int x){
    memset(dist,inf,sizeof(dist));
    priority_queue<pi> mq;
    mq.push(make_pair(0,x));
    dist[x]=0;
    while(!mq.empty()){
        int j = mq.top().second;
        int distance = mq.top().first;
        mq.pop();
        for(int p = h[j];~p;p = ne[p]){
            int q = e[p];//q是终点
            if(distance+w[p]<dist[q]){
                dist[q] = distance+w[p];
                mq.push(make_pair(dist[q],q));
                pre[q] = j;
            }
        }
    }
}
void solve(){
    string s;
    string a,b;
    idx1 = 1;
    idx = 0;
    mmp.clear();
    if0(n)cin>>s;
    memset(h,-1,sizeof(h));
    if0(m){
        cin>>a>>b>>c;
        if(mmp[a]==0){
            xiufu[idx1] = a;
            mmp[a] = idx1++;
        }
        if(mmp[b]==0){
            xiufu[idx1] = b;
            mmp[b] = idx1++;
        }
        add(mmp[a],mmp[b],c);
    }
    cin>>a>>b;
    memset(pre,-1,sizeof(pre));
    dijsktra(mmp[a]);
    stack<string>wedg;
    int en = mmp[b];
    while(en!=-1){
        wedg.push(xiufu[en]);
        en = pre[en];
    }
    cout<<dist[mmp[b]]<<endl;
    while(!wedg.empty()){
        cout<<wedg.top()<<" ";
        wedg.pop();
    }
    cout<<endl;
    
}
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    //cout.tie(nullptr); 
    while(1){
        cin>>n>>m;
        if(m==0&&n==0)break;
        solve();
    }
    
    return 0;
}

基于广度优先搜索的六度空间

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long

typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
vector<int> wedg[10005];
bool marked[10005];
int frend;
int m,n;
queue<pi>mq;
void bfs(){
    while(!mq.empty()){
        auto j = mq.front();
        mq.pop();
        if(marked[j.first]||j.second>6)continue;
        marked[j.first]=1;
        frend++;
    for(auto t:wedg[j.first]){
        if(!marked[t])mq.push(make_pair(t,j.second+1));
    }
    }


}
void solve(){
    if0(m){
        int a,b;
        cin>>a>>b;
        wedg[a].push_back(b);
        wedg[b].push_back(a);
    }
    if1(n){
        double ans;
        memset(marked,0,sizeof(marked));
        frend = 0;
        mq.push({i,0});
        bfs();
        ans = 1.*(frend)/n;
        printf("%d:%.2f%\n",i,ans*100);

    }
    if1(n)wedg[i].clear();
}
int main(){
    while(1){
    cin>>n>>m;
    if(n==0&&m==0)return 0;
    solve();
    }
   // getchar();
    
    return 0;
}

排序算法的实现与分析

归并法

/*
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long

typedef  pair<int,int> pi ;
#define if1(x) for(int i =1 ;i<=x;i++)
#define if0(x) for(int i = 0;i<x;i++)
#define jf0(x) for(int j = 0;j<x;j++)
#define jf1(x) for(int j = 1;j<=x;j++)
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
struct node{
    string name;
    double grade;
};
bool cmp(node a,node b){
    return a.grade>b.grade;
}
void hebin(vector<node>& da,int l,int r,int mid){
    node* temp = new node[r-l+2];
    int i = l,j = mid+1,k=0;
    while(i<=mid&&j<=r){
        if(cmp(da[i],da[j])){
            temp[k++] = da[i++];
        }else{
            temp[k++] = da[j++];
        }
    }
    while(i<=mid)
    temp[k++] = da[i++];
    while(j<=r) temp[k++] = da[j++];
    k=0;
    for(int i = l; i<=r;)da[i++] = temp[k++];
    delete []temp;
}
void guibin(int l,int r,vector<node>& da){
    if(l<r){
        int mid = l+r>>1;
        guibin(l,mid,da);
        guibin(mid+1,r,da);
        hebin(da,l,r,mid);
    }
}
int main(){
    string s;
    double grade;
    vector<node> date;
    while(1){
        cin>>s>>grade;
        if(s=="0"&&grade==0)break;
        node te ;
        te.grade = grade;
        te.name = s;
        date.push_back(te);
    }
   guibin(0,date.size()-1,date);
    
    if0(date.size()){
        cout<<date[i].name<<" ";
        printf("%.2f\n",date[i].grade);
    }
    return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/111332.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

二叉树(9.7)

目录 1.树概念及结构 1.1树的概念 1.2 树的相关概念 1.3 树的表示 2.二叉树概念及结构 2.1概念 2.2 特殊的二叉树 2.4 二叉树的存储结构 3.二叉树顺序结构及实现 3.1 二叉树的顺序结构 3.2 堆的概念及结构 1.树概念及结构 1.1树的概念 前面我们学习的都是组成简…

SpringBoot面试题8:运行 Spring Boot 有哪几种方式?Spring Boot 需要独立的容器运行吗?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:运行 Spring Boot 有哪几种方式? 运行Spring Boot应用有多种方式,具体取决于你的需求和环境。以下是几种常见的运行Spring Boot应用的方式: 使…

springboot+vue基于Hadoop短视频流量数据分析与可视化系统的设计与实现【内含源码+文档+部署教程】

博主介绍&#xff1a;✌全网粉丝10W,前互联网大厂软件研发、集结硕博英豪成立工作室。专注于计算机相关专业毕业设计项目实战6年之久&#xff0c;选择我们就是选择放心、选择安心毕业✌ &#x1f345;由于篇幅限制&#xff0c;想要获取完整文章或者源码&#xff0c;或者代做&am…

【计算机网络】数据链路层——以太网

文章目录 前言什么是以太网以太网帧格式6位目的地址和源地址2位类型数据长度CRC 校验和 数据在数据链路层是如何转发的 前言 前面我们学习了关于应用层——自定义协议、传输层——UDP、TCP协议、网络层——IP协议&#xff0c;今天我将为大家分享关于数据链路层——以太网方面的…

金蝶云星空创建自动下推并保存公共服务

文章目录 金蝶云星空创建自动下推并保存公共服务创建公共方法按单下推数据按明细行下推数据调用下推操作 调用公共方法 金蝶云星空创建自动下推并保存公共服务 创建公共方法 按单下推数据 /// <summary>/// 获取单据转换数据包/// </summary>public DynamicObjec…

RIS辅助MIMO广播信道容量

RIS辅助MIMO广播信道容量 摘要RIS辅助的BC容量矩阵形式的泰勒展开学习舒尔补 RIS-Aided Multiple-Input Multiple-Output Broadcast Channel Capacity论文阅读记录 基于泰勒展开求解了上行容量和最差用户的可达速率&#xff0c;学习其中的展开方法。 摘要 Scalable algorithm…

UE4 使用材质后期 制作玻璃有雨效果

效果展示&#xff0c;其实这是一个动画效果 以上为所有逻辑 拿到TexCoord给到Panner&#xff0c;Time和Speed都是通过下面计算而来&#xff0c;后面讲&#xff0c;再拿到时间和速度值过后&#xff0c;加上扰动值&#xff0c;最后取G值&#xff0c;因为雨事从上而下的动&#xf…

【AIFEM案例操作】电器盒谐响应分析

AIFEM是由天洑自主研发的一款通用的智能结构仿真软件&#xff0c;助力用户解决固体结构相关的静力学、动力学、振动、热力学等实际工程问题&#xff0c;软件提供高效的前后处理工具和高精度的有限元求解器&#xff0c;帮助用户快速、深入地评估结构的力学性能&#xff0c;加速产…

微信小程序项目案例之导游证考试刷题小程序

前言 很多计算机专业的同学在做毕设选题时不知道该如何选题&#xff0c;有的同学是已经选择了要开发一款小程序&#xff0c;但是又不知道开发哪类小程序。本篇将为大家介绍一个小程序的开发方向&#xff0c;考试刷题类小程序是目前比较火的小程序项目之一&#xff0c;在小程序…

JavaScript基础知识19——循环结构:while循环

哈喽&#xff0c;你好&#xff0c;我是雷工。 本节学习JavaScript基础语法的循环结构&#xff1a;while循环&#xff0c;以下为学习笔记。 while循环 循环概念&#xff1a;重复执行一些操作&#xff1b; 循环特征&#xff1a;不断地重复&#xff1b; while&#xff1a;在…期间…

面向Three.js开发者的3D自动纹理化开发包

DreamTexture.js 是面向 three.js 开发者的 3D 模型纹理自动生成与设置开发包&#xff0c;可以为 webGL 应用增加 3D 模型的快速自动纹理化能力。 图一为原始模型, 图二图三为贴图后的模型。提示词&#xff1a; city, Realistic , cinematic , Front view ,Game scene graph 1、…

Kitex踩坑 [Error] KITEX: processing request error,i/o timeout

报错问题 2023/010/28 17:20:10.250768 default_server_handler.go:234: [Error] KITEX: processing request error, remoteService, remoteAddr127.0.0.1:65425, errordefault codec read failed: read tcp 127.0.0.1:8888->127.0.0.1:65425: i/o timeout 分析原因 Hert…

基于dockerfile搭建lnmp

目录 任务需求&#xff1a; 一、规划&#xff1a; 二、准备&#xff1a; 三、部署nginx容器&#xff08;172.18.0.10&#xff09;&#xff1a; 1.编写Dockerfile构建镜像&#xff1a; 2.准备nginx配置文件&#xff1a; 3.构建镜像&#xff0c;启动nginx容器&#xff1a; 四…

【QT】事件分发器

event事件分发器&#xff0c;用于分发事件&#xff0c;在这里也可以做拦截&#xff0c;返回值boo。如果返回的是true代表拦截处理&#xff0c;不再向下分发。 展示事件拦截 上一段代码&#xff1a;【QT】鼠标常用事件-CSDN博客 代码 // 事件分发器 // 拦截鼠标按下 // QEven…

四十二、【进阶】

目录 1、覆盖索引 2、案例分析 &#xff08;1&#xff09;select * 查询 &#xff08;2&#xff09;使用字段查询 &#xff08;3&#xff09;性能差异原因 3、分析 &#xff08;1&#xff09;主键id查询 &#xff08;2&#xff09;覆盖索引 1、覆盖索引 简单点说&#x…

Nginx 部署多个安全域名,多个服务【工作记录】

以下是本人通过Docker 部署的Nginx挂载出来的文件目录 先看下 nginx.conf 配置文件内容&#xff1a;如下 ps&#xff1a;当前文件就是安装后的初始内容&#xff0c;无修改。主要关注最后一行 include /etc/nginx/conf.d/*.conf;表示引入其他目录下的.conf配置文件&#xff1b;…

【Arduino环境下驱动合宙esp32c3单片机基本外设】

【esp32c3基本外设驱动】 1. GPIO调试1.1 源码分享2.2 实验效果 2. ADC调试2.1 源码分享2.2 实验效果 3. WS2812驱动3.1 源码分享3.2 实验效果 4. 旋转编码器4.1 源码分享4.2 测试效果 5. SSD1306屏幕驱动5.1 源码分享5.2 测试效果 6. 双cpu同时工作测试6.1 源码分享6.2 测试效…

Arrays,Arrays重载的sort方法

Arrays -1的原因.因为返回正数不就是表示存在只能是负数 Arrays重载的sort方法 //这个方法只能给引用数据类型排序 //如果是基本数据类型需要转化为对应的包装类 public class arrays {public static void main(String[] args) {Integer arr[]{2,1,4,6,3,5,8,7,9};Arrays.s…

学习笔记3——JVM基础知识

学习笔记系列开头惯例发布一些寻亲消息 链接&#xff1a;https://baobeihuijia.com/bbhj/contents/3/196593.html JVM&#xff08;Write Once&#xff0c;Run Anywhere&#xff09; 以下是一些学习时有用到的资料&#xff0c;只学习了JVM的基础知识&#xff0c;对JVM整体进…

python爬虫—使用xpath方法进行数据解析

1. 背景信息 爬取安居客二手房源信息 URL地址&#xff1a;https://wuhan.anjuke.com/sale/?fromnavigation 2. 代码实现 import requests from lxml import etreeif __name__ __main__:# 1.指定URLurl "https://wuhan.anjuke.com/sale/?fromnavigation"# 2.U…
最新文章