S. Segmentation——CodeForces

S. Segmentation

题目链接:http://codeforces.com/gym/101806/problem/S

题目内容:

 

ZOYI is developing a tool called Channel which offers a tool to talk with online users in the site. Recently, ZOYI introduced a RF(Recency / Frequency) Model to distinguish users who are using the Channel and decided to classify the users through following calculations.

Figure : Distinguishing users in RF Channel. Horizontal axis represents Recency, while vertical axis represents Frequency.

(0 < f1 < f2 < f3 < f4, 0 < r1 < r2 < r3 < r4, all fi and ri are integers.)

x axis represents Recency and y axis represents Frequency. All online users are given values r,  f by their connection record, and are classified into one of twelve conditions shown below.

  • "New Customer"
  • "Promising"
  • "About to Sleep"
  • "Hibernating"
  • "Lost"
  • "Potential Loyalist"
  • "Need Attention"
  • "About to Leave"
  • "Champion"
  • "Loyal Customer"
  • "Can't Lose Them"
  • "None"

Among those, "None" means the user has no connection record to the server. If (r,  f) is located on two or more classification boundaries, it follows the classification of (r - 0.5, f - 0.5). For example, if the value of (r,  f) is (r4,  f2) it is classified as "Hibernating", while if the value is (r3,  f4), it is classified as "Loyal Customer".

You want to investigate users' statuses who are interested in RUN, so you are trying to install the program in the following way :

  • r: if the current time is t (most recent access time)
  • f: number of visited times

Given events of site users, make a program which classifies the users following the given picture above.

  • Input:

First line contains four space-separated integers r1,  r2,  r3,  r4. (0 < r1 < r2 < r3 < r4 ≤ 10, 000)

Second line consists four space-separated integers f1,  f2,  f3,  f4. (0 < f1 < f2 < f3 < f4 ≤ 10, 000)

Third line contains a single integer N. (1 ≤ N ≤ 100, 000)

Next N lines contains events in time order, where ith element represents the event held at time i.

Each event is given as space-separated A and B, where B is the username which contains no whitespace with at most 10 alphabets. A has a value of 1 or 2, where 1 means the user entered the site while 2 means you should print how the user is classified.

  • Output:

For events where A is 2, print how the user is classified in each line (without quotes).

  • Sample

Input

1 2 3 4
1 2 3 4
8
1 RUN
1 Alex
2 Alex
1 RUN
1 RUN
1 Alex
2 Alex
2 RUN

Output

New Customer
Potential Loyalist
Need Attention
  • Note

The connection status of Alex is f = 1 (first visit), r = 1 (time 3 - 2 = 1) at time 3. Thus, Alex is classified as "New Customer".

At time 7, the connection status of Alex is f = 2 (second visit), r = 1 (time 7 - 6 = 1). Thus, Alex is classified as "Potential Loyalist".

At time 8, the connection status of RUN is f = 3 (third visit), r = 3 (time 8 - 5 = 3). Thus, RUN is classified as "Need Attention".

题目分析:

题目很长,而且全是英文,需要花大量的时间进行阅读,但题目还是比较容易的。大概意思就是 一个公司想根据根据 R (用户最近的一次使用) 和 F(用户使用的频率) 来对用户进行了划分,也就是图片内容所示。然后 就是输入 用户的访问情况 ,若为 2 则你需要根据用户的 R 和 F 算出 此时用户被划分在哪个区间了。

我先定义了一个 struct结构体 Value 来保存 R 和 F信息,然后对于每个用户 使用 map<string,Value>,其中string为 用户名,然后 Value 为用户保存用户的 R 和F ,需要注意一下 None的情况 就是 用户还没使用就直接 询问 用户的划分情况 (也就是在输入中  2 用户  出现 在 1  用户之前) 再使用 point 函数 进行分类输入即可。

#include <iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;

// 用一个 map<string,struct> ,struct 中存就是 f和r

int r1, r2, r3, r4;
int f1, f2, f3, f4;
struct Value{
	int f, r;
};
map<string, Value>m;
void point(double r,double f) {
	
	if (r <= r1) {
		if (f <= f1) {
			cout << "New Customer" << endl;
		}
		else if (f > f1&&f <= f3) {
			cout << "Potential Loyalist" << endl;
		}
		else if (f > f3&&f <= f4) {
			cout << "Loyal Customer" << endl;
		}
		else if (f > f4) {
			cout << "Champion" << endl;
		}

	}
	else if (r > r1&&r <= r2) {
		if (f <= f1) {
			cout << "Promising" << endl;
		}
		else if (f > f1&&f <= f3) {
			cout << "Potential Loyalist" << endl;
		}
		else if (f > f3) {
			cout << "Loyal Customer" << endl;
		}

	}
	else if (r > r2&&r <= r3) {
		if (f <= f2) {
			cout << "About to Sleep" << endl;
		}
		else if (f > f2&&f <= f3) {
			cout << "Need Attention" << endl;
		}
		else if (f > f3) {
			cout << "Loyal Customer" << endl;
		}
	}
	else if (r > r3&&r <= r4) {
		if (f <= f1) {
			cout << "Lost" << endl;
		}
		else if (f > f1&&f <= f2) {
			cout << "Hibernating" << endl;
		}
		else if (f > f2) {
			cout << "About to Leave" << endl;
		}
	}
	else if (r>r4) {
		if (f <= f2) {
			cout << "Lost" << endl;
		}
		else if (f > f2&&f<=f4) {
			cout << "About to Leave" << endl;
		}
		else if (f > f4) {
			cout << "Can't Lose Them" << endl;
		}
	}
}
int main()
{
	cin >> r1 >> r2 >> r3 >> r4;
	cin >> f1 >>f2 >> f3 >> f4;
	int n;
	cin >> n;
	int num;
	int time=1;
	string s;
	while (n--) {
		cin >> num >> s;
		if (num == 1) {
			if (m.find(s)==m.end()) {    //判断用户是否存在
				Value v;
				v.f = 1;
				v.r = time;
				m[s] = v;
			}
			else {
				m[s].f++;
				m[s].r = time;
			}
	}
		else if (num == 2) {
			if (m.find(s) == m.end()) {
				cout << "None" << endl;
			}
			else point(time-m[s].r-0.5, m[s].f-0.5);  //向左下区间倾斜
			//else point(time - m[s].r, m[s].f);   经过尝试可以不减0.5
		}
		time++;
	}
	return 0;
}

 

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值