A. Knight Tournament SET的应用

博客讲述了Berland的骑士锦标赛,有n个骑士参赛,共m场战斗,每场战斗有特定范围的骑士参与,只有获胜者能继续参赛,最后一场获胜者为锦标赛冠军。要求编写代码计算每个骑士被谁击败,还给出了输入输出要求及示例。
A. Knight Tournament
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event.

As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tournament (it was a weekend, after all). Now you are really curious about the results of the tournament. This time the tournament in Berland went as follows:

 

  • There are n knights participating in the tournament. Each knight was assigned his unique number — an integer from 1 to n.
  • The tournament consisted of m fights, in the i-th fight the knights that were still in the game with numbers at least li and at most rihave fought for the right to continue taking part in the tournament.
  • After the i-th fight among all participants of the fight only one knight won — the knight number xi, he continued participating in the tournament. Other knights left the tournament.
  • The winner of the last (the m-th) fight (the knight number xm) became the winner of the tournament.

 

You fished out all the information about the fights from your friends. Now for each knight you want to know the name of the knight he was conquered by. We think that the knight number b was conquered by the knight number a, if there was a fight with both of these knights present and the winner was the knight number a.

Write the code that calculates for each knight, the name of the knight that beat him.

Input

The first line contains two integers nm (2 ≤ n ≤ 3·105; 1 ≤ m ≤ 3·105) — the number of knights and the number of fights. Each of the following m lines contains three integers li, ri, xi (1 ≤ li < ri ≤ nli ≤ xi ≤ ri) — the description of the i-th fight.

It is guaranteed that the input is correct and matches the problem statement. It is guaranteed that at least two knights took part in each battle.

Output

Print n integers. If the i-th knight lost, then the i-th number should equal the number of the knight that beat the knight number i. If the i-th knight is the winner, then the i-th number must equal 0.

Sample test(s)
input
4 3
1 2 1
1 3 3
1 4 4
output
3 1 4 0 
input
8 4
3 5 4
3 7 6
2 8 8
1 8 1
output
0 8 4 6 4 8 6 1 
Note

Consider the first test case. Knights 1 and 2 fought the first fight and knight 1 won. Knights 1 and 3 fought the second fight and knight 3 won. The last fight was between knights 3 and 4, knight 4 won.

/*
 * Author: 
 * Created Time:  2013/11/7 20:07:35
 * File Name: D.cpp
 * solve: D.cpp
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<stack>
#include<set>
#include<iostream>
#include<vector>
#include<queue>
//ios_base::sync_with_stdio(false);
//#pragma comment(linker, "/STACK:1024000000,1024000000")

using namespace std;
#define sz(v) ((int)(v).size())
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define repf(i, a, b) for (int i = (a); i <= (b); ++i)
#define repd(i, a, b) for (int i = (a); i >= (b); --i)
#define clr(x) memset(x,0,sizeof(x))
#define clrs( x , y ) memset(x,y,sizeof(x))
#define out(x) printf(#x" %d\n", x)
#define sqr(x) ((x) * (x))
typedef long long LL;

const int INF = 1000000000;
const double eps = 1e-8;
const int maxn = 300010;

int sgn(const double &x) {  return (x > eps) - (x < -eps); }

set<int> Left;
vector<int> temp;
int p[maxn];
int main() 
{
    //freopen("in.txt","r",stdin);
    int n,m;
    while(scanf("%d%d",&n,&m)==2)
    {
        Left.clear();
        repf(i,1,n)
            Left.insert(i);
        clr(p);
        repf(i,1,m)
        {
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            set<int> :: iterator it  = Left.lower_bound(a);

            for(;*it<=b && it != Left.end();it++)
            {
                if(*it != c)
                {
                    p[*it] = c;
                    temp.push_back(*it);
                }
            }
            rep(j,0,temp.size())
                Left.erase(temp[j]);
            temp.clear();
        }

        repf(i,1,n)
            if(p[i] == i)
                p[i] = 0;
        cout<<p[1];
        repf(i,2,n)
            printf(" %d",p[i]);
        cout<<endl;
    }
    return 0;
}

 

 

转载于:https://www.cnblogs.com/DreamHighWithMe/p/3413162.html

### 解决 Python 中 pymoo 库的 ModuleNotFoundError 错误 当遇到 `ModuleNotFoundError` 提示无法找到 `'pymoo.operators.selection.tournament_selection'` 模块时,通常是因为以下几个原因之一引起的:模块路径发生了变化、版本不兼容或者是未正确安装库文件。 #### 可能的原因分析 1. **模块路径变更**:在较新的 pymoo 版本中,某些子模块的位置可能会发生变化。例如,`tournament_selection` 已经不再位于 `pymoo.operators.selection` 下面,而是移动到了其他位置[^1]。 2. **版本冲突**:如果使用的 pymoo 版本过旧或过新,可能导致代码中的模块引用失效。这通常是由于官方文档更新滞后造成的[^2]。 3. **环境配置问题**:Python 环境可能存在多个版本的 pymoo 或者依赖项缺失的情况,从而引发此类错误[^3]。 --- ### 解决方案 #### 方法一:确认正确的模块路径 根据最新的 pymoo 文档和源码结构,`TournamentSelection` 类已经被重新组织到不同的命名空间下。现在应该通过如下方式引入该类: ```python from pymoo.operators.selection.tournament import TournamentSelection ``` 注意这里的区别在于原路径 (`pymoo.operators.selection`) 和新路径 (`pymoo.operators.selection.tournament`) 的不同之处[^1]。 #### 方法二:升级或降级 pymoo 到合适版本 确保所用 pymoo 版本与项目需求匹配非常重要。可以通过 pip 命令查看已安装版本号并执行相应操作: - 查看当前 pymoo 版本: ```bash pip show pymoo ``` - 升级至最新稳定版: ```bash pip install --upgrade pymoo ``` - 若需回退到特定历史版本,则运行命令如: ```bash pip install pymoo==0.6.0 ``` > 注意:每次更改后记得重启开发工具(IDE/Jupyter Notebook),以使改动生效[^2]。 #### 方法三:验证虚拟环境独立性 为了避免全局环境中存在的干扰因素影响正常工作流,建议创建一个新的隔离型 venv 并单独管理所需包集合: ```bash # 创建名为 my_env 的全新虚拟环境 python -m venv my_env # 启动激活它 source my_env/bin/activate # Linux/macOS 用户适用 my_env\Scripts\activate # Windows 用户适用 # 在干净状态下重装必要组件 pip install pymoo numpy scipy matplotlib ... ``` 完成之后再次测试脚本能否顺利加载所需的 tournament selection 功能模块即可[^3]。 --- ### 总结提示 综上所述,针对 `ModuleNotFoundError: No module named 'pymoo.operators.selection.tournament_selection'` 这个异常情况可以从三个方面入手排查原因并采取对应措施加以修复。即核实 API 接口变动记录;同步调整本地软件栈级别设定;以及重构专属作业区避免外部污染风险。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值