Abbyy Cup 2.0 - Final (unofficial) A1(贪心)

CF 207A

A1. Beaver's Calculator 1.0
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be used in a variety of scientific problems.

To test it, the Smart Beaver invited n scientists, numbered from 1 to n. The i-th scientist brought ki calculating problems for the device developed by the Smart Beaver from ABBYY. The problems of the i-th scientist are numbered from 1 to ki, and they must be calculated sequentially in the described order, since calculating each problem heavily depends on the results of calculating of the previous ones.

Each problem of each of the n scientists is described by one integer ai, j, where i (1 ≤ i ≤ n) is the number of the scientist, j (1 ≤ j ≤ ki) is the number of the problem, and ai, j is the number of resource units the calculating device needs to solve this problem.

The calculating device that is developed by the Smart Beaver is pretty unusual. It solves problems sequentially, one after another. After some problem is solved and before the next one is considered, the calculating device allocates or frees resources.

The most expensive operation for the calculating device is freeing resources, which works much slower than allocating them. It is therefore desirable that each next problem for the calculating device requires no less resources than the previous one.

You are given the information about the problems the scientists offered for the testing. You need to arrange these problems in such an order that the number of adjacent "bad" pairs of problems in this list is minimum possible. We will call two consecutive problems in this list a "bad pair" if the problem that is performed first requires more resources than the one that goes after it. Do not forget that the problems of the same scientist must be solved in a fixed order.

Input

The first line contains integer n — the number of scientists. To lessen the size of the input, each of the next n lines contains five integers kiai, 1xiyimi (0 ≤ ai, 1 < mi ≤ 1091 ≤ xi, yi ≤ 109) — the number of problems of the i-th scientist, the resources the first problem requires and three parameters that generate the subsequent values of ai, j. For all j from 2 to ki, inclusive, you should calculate value ai, j by formulaai, j = (ai, j - 1 * xi + yi) mod mi, where a mod b is the operation of taking the remainder of division of number a by number b.

To get the full points for the first group of tests it is sufficient to solve the problem with n = 21 ≤ ki ≤ 2000.

To get the full points for the second group of tests it is sufficient to solve the problem with n = 21 ≤ ki ≤ 200000.

To get the full points for the third group of tests it is sufficient to solve the problem with 1 ≤ n ≤ 50001 ≤ ki ≤ 5000.

Output

On the first line print a single number — the number of "bad" pairs in the optimal order.

If the total number of problems does not exceed 200000, also print  lines — the optimal order of the problems. On each of these lines print two integers separated by a single space — the required number of resources for the problem and the number of the scientist who offered this problem, respectively. The scientists are numbered from 1 to n in the order of input.

Examples
input
2
2 1 1 1 10
2 3 1 1 10
output
0
1 1
2 1
3 2
4 2
input
2
3 10 2 3 1000
3 100 1 999 1000
output
2
10 1
23 1
49 1
100 2
99 2
98 2
Note

In the first sample n = 2k1 = 2a1, 1 = 1a1, 2 = 2k2 = 2a2, 1 = 3a2, 2 = 4. We've got two scientists, each of them has two calculating problems. The problems of the first scientist require 1 and 2 resource units, the problems of the second one require 3 and 4 resource units. Let's list all possible variants of the calculating order (each problem is characterized only by the number of resource units it requires):(1, 2, 3, 4)(1, 3, 2, 4)(3, 1, 2, 4)(1, 3, 4, 2)(3, 4, 1, 2)(3, 1, 4, 2).

Sequence of problems (1, 3, 2, 4) has one "bad" pair (3 and 2), (3, 1, 4, 2) has two "bad" pairs (3 and 14 and 2), and (1, 2, 3, 4) has no "bad" pairs.


题解:贪心。

#include<iostream>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
vector<pair<pair<int,int>,int> > v;

int main()
{
	int n;
	cin>>n;
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		int k,a,x,y,m;
		cin>>k>>a>>x>>y>>m;
		int p=0,b=0;
		for (int j=1;j<=k;j++)
		{
			if (a<b) p++;//坏对数 
			if (v.size()<=200000) 
				v.push_back(make_pair(make_pair(p,a),i));
			b=a;
			a=((long long)a*x+y)%m;
		}
		ans=max(ans,p);
	}
	cout<<ans<<endl;
	if (v.size()<=200000)
	{
		sort(v.begin(),v.end());
		for (int i=0;i<v.size();i++)
			printf("%d %d\n",v[i].first.second,v[i].second);
	}
	return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ABBYY FineReader是一款功能非常强大的OCR(光学字符识别)软件。它可以将纸质文档、PDF文件、扫描图片等各种类型的文件转换为可编辑的文字文档或可搜索的PDF文档。此外,ABBYY FineReader还具有多种语言支持、格式转换、自动矫正、表格处理等多种功能,可大大提高工作效率。其界面简洁易懂,操作便捷,即使没有专业技能的用户也可以快速上手。另外还可以设置自动识别和分类等功能。 ABBYY FineReader 可以处理多种不同语言,而且可以快速检测出文档中的错误或变形字符,帮助用户更精准的识别文档内容。同时,ABBYY FineReader 也能够支持自动扫描文件,并且能自动分类,方便用户更好进行管理。此外,它还支持自动矫正、表格识别、图片修复等多项功能,通过训练机器学习算法,可以极大提高检索文档精准率和准确性等维度的表现。总的来说,ABBYY FineReader不仅提高了工作效率和效果,而且为我们生活和工作带来便利。 ### 回答2: ABBYY FineReader是一款识别文字、图片和表格的OCR(Optical Character Recognition,光学字符识别)软件。这款软件可以将扫描的文档自动识别文字,并且可以对识别后的文字进行编辑和格式化。 使用ABBYY FineReader可以大大提高文档的处理效率,减少重复的输入和校对工作。同时,它还具备阅读PDF文档、截取屏幕、批量转换文件格式等实用功能,使得用户的工作更加高效便捷。 此外,ABBYY FineReader还具有多语言识别能力,可以识别包括中文在内的多种语言文本,极大地方便了国际交流和跨国业务的处理。 总之,ABBYY FineReader是一款非常实用的 OCR 软件,可以通过自动化识别、提取和转换文字帮助我们快速完成文档处理。 ### 回答3: ABBYY FineReader是一款优秀的光学字符识别(OCR)软件,它可以将纸质文档或扫描文档转换为可编辑、可搜索的数字文本。该软件支持多种文件格式,如PDF、图片(JPEG、PNG、TIFF等)等,并支持多国语言识别,能够准确识别基于中文、英文、日文、韩文等多种语言的文本。 该软件提供了多种工具和功能,例如划定区域、调整识别精度、批量处理多个文件等。此外,ABBYY FineReader还支持PDF文档的转换成Word、Excel、PowerPoint等格式,方便用户对文档进行编辑和共享。 除此之外,ABBYY FineReader还有一些独特的特点,例如识别表格和条形码等,这使得该软件在商业和办公场景下具有广泛的应用价值。 总之,ABBYY FineReader可以说是一款功能齐全、易于使用、准确识别的OCR软件,为用户节省了大量的时间和精力,并提高了文档处理的效率和准确性。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值