本文出自:http://blog.csdn.net/svitter

原题:http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624

题意:为什么每次都是我做这么坑爹的题目TAT

一开始的名字我在想名字有没有空格,就像是之前

Sdut2411 Pixel density 山东省第三届ACM省赛(输入输出字符串处理)

这道题目,以至于第一篇WA我根本想不出到底是name的问题还是其他方面的问题。后来证明果然是没读懂题意,哎,坑爹啊。

给你五个数 n,s, x,  y , mod,然后输入n行数据,以Team_name +"request"+num+"pages."的形式给你。

然后就出现坑了。

这句话。the printer will break down when the printed pages counter reached s(s is generated by the function s=(s*x+y)%mod ) and then the
counter will become 0. In the same time the last request will be reprint from the very begin if it isn't complete yet(The data guaranteed that every request will be completed in some time).

我的理解是,每当数量达到s,那么调用生成函数生成新的s,如果之前的没有打印完,那么重新全部打印出来。

但是事实上,是超过s的话,那么。。。。。。下面是我的AC代码,if前面的注释就是我先前的代码,问题就出在只要到达s(正好等于也算),那么就更新s。= =然后我就呵呵的WA了。(这两个的差距就在于是否多输出一个0.)

- -结合实践的话确实也能想明白- -就是你正好打完了你还更新s干什么。。。

下面是两个思路的AC代码:

//============================================================================
// Name : 省赛字符串.cpp
// Author : Vit
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; struct Team
{
char name[21];
int num;
}; Team te[102]; int n, s, x, y, mod; void update(int &s)
{
s = ((s * x) % mod + y % mod) % mod;
if(s == 0)
update(s);
}
void print(int i)
{
printf("%d pages for %s\n", te[i].num, te[i].name);
}
void print(int i, int num)
{
printf("%d pages for %s\n", num, te[i].name);
} void ace()
{
//work point
int i, t;
//num;
//freopen("test", "r", stdin);
scanf("%d", &t);
while (t--)
{
//input data
scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod);
for (i = 0; i < n; i++)
{
scanf("%s request %d pages", te[i].name, &te[i].num);
} int sum = 0; //handle data
for (i = 0; i < n; i++)
{
sum += te[i].num;
// if(sum == s)
// {
// print(i)
// update(s);
// sum = 0;
// }
// else
if(sum > s)
{
print(i, te[i].num + (s - sum));
update(s);
sum = 0;
i--;
}
else
{
print(i);
}
} //end of i
printf("\n");
} // end of t;
} int main()
{
ace();
return 0;
}

第二种:

//============================================================================
// Name : 省赛字符串.cpp
// Author : Vit
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================ #include <iostream>
#include <stdio.h>
#include <string.h> using namespace std; struct Team
{
char name[21];
int num;
}; Team te[102]; int n, s, x, y, mod; void update(int &s)
{
s = ((s * x) % mod + y % mod) % mod;
if(s == 0)
update(s);
}
void print(int i)
{
printf("%d pages for %s\n", te[i].num, te[i].name);
}
void print(int i, int num)
{
printf("%d pages for %s\n", num, te[i].name);
} void ace()
{
//work point
int i, t;
//num;
//freopen("test", "r", stdin);
scanf("%d", &t);
while (t--)
{
//input data
scanf("%d%d%d%d%d", &n, &s, &x, &y, &mod);
for (i = 0; i < n; i++)
{
scanf("%s request %d pages", te[i].name, &te[i].num);
} int sum = s; //handle data
for (i = 0; i < n; i++)
{
if(sum >= te[i].num)
{
print(i);
sum -= te[i].num;
}
else if(sum < te[i].num)
{
print(i, sum);
update(s);
sum = s;
i--;
}
} //end of i
printf("\n");
} // end of t;
} int main()
{
ace();
return 0;
}
作者:svitter 发表于2014-5-4 17:12:46 原文链接
阅读:200 评论:1 查看评论

[原]sdut2624 Contest Print Server (大水+大坑)山东省第四届ACM省赛的更多相关文章

  1. 山东省第四届ACM省赛

    排名:http://acm.sdut.edu.cn/sd2012/2013.htm 解题报告:http://www.tuicool.com/articles/FnEZJb A.Rescue The P ...

  2. [原]sdut2605 A^X mod P 山东省第四届ACM省赛(打表,快速幂模思想,哈希)

    本文出自:http://blog.csdn.net/svitter 题意: f(x) = K, x = 1 f(x) = (a*f(x-1) + b)%m , x > 1 求出( A^(f(1) ...

  3. 2013年山东省第四届ACM大学生程序设计竞赛-最后一道大水题:Contest Print Server

    点击打开链接 2226: Contest Print Server Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 53  Solved: 18 [Su ...

  4. 山东省赛J题:Contest Print Server

    Description In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source c ...

  5. 模拟 2013年山东省赛 J Contest Print Server

    题目传送门 /* 题意:每支队伍需求打印机打印n张纸,当打印纸数累计到s时,打印机崩溃,打印出当前打印的纸数,s更新为(s*x+y)%mod 累计数清空为0,重新累计 模拟简单题:关键看懂题意 注意: ...

  6. 2013年山东省第四届ACM大学生程序设计竞赛J题:Contest Print Server

    题目描述     In ACM/ICPC on-site contests ,3 students share 1 computer,so you can print your source code ...

  7. sdutoj 2624 Contest Print Server

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2624 Contest Print Server ...

  8. 山东省第四届ACM大学生程序设计竞赛解题报告(部分)

    2013年"浪潮杯"山东省第四届ACM大学生程序设计竞赛排名:http://acm.upc.edu.cn/ranklist/ 一.第J题坑爹大水题,模拟一下就行了 J:Contes ...

  9. 山东省第四届ACM程序设计竞赛部分题解

    A : Rescue The Princess 题意: 给你平面上的两个点A,B,求点C使得A,B,C逆时针成等边三角形. 思路: http://www.cnblogs.com/E-star/arch ...

随机推荐

  1. MySQL优化技巧之三(索引操作和查询优化)

    对于任何DBMS,索引都是进行优化的最主要的因素.对于少量的数据,没有合适的索引影响不是很大,但是,当随着数据量的增加,性能会急剧下降.如果对多列进行索引(组合索引),列的顺序非常重要,MySQL仅能 ...

  2. Python进阶08 异常处理

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 本文特别感谢kylinfish的纠正,相关讨论见留言区. 异常处理 在项目开发中, ...

  3. TestNG运作报错An interanl error occurred during:"Launching first"

    备注:我建的类名就叫做“first” 解决办法:卸载掉TestNG M2E Help-->Install new software-->What is already installed? ...

  4. 有向无环图(DAG)的最小路径覆盖(转)

    DAG的最小路径覆盖 定义:在一个有向图中,找出最少的路径,使得这些路径经过了所有的点. 最小路径覆盖分为最小不相交路径覆盖和最小可相交路径覆盖. 最小不相交路径覆盖:每一条路径经过的顶点各不相同.如 ...

  5. 剑指Offer:面试题13——在O(1)时间删除链表结点

    问题描述: 给定单向链表的头指针和一个结点指针,定义一个函数在O(1)时间删除该结点.链表结点与函数的定义如下: public class ListNode{ int value; ListNode ...

  6. android 解决ScrollView嵌套ListView的问题,不能全屏,全屏不能显示下面控件

    在开发中遇到ScrollView嵌套ListView的问题,最开始发出不能全屏,效果是这样的: 但我想要的效果是这样的: 下面看一下布局文件: <?xml version="1.0&q ...

  7. 使用virtualbox安装centos虚拟机,以及VirtualBox无法安装64位Linux CentOS的解决办法

    之前一直用vmware的虚拟机,好吧,其实一直盗版挺不好的,然后想用centos搭点东西,结果在vmare上安装centos总是有些问题,看了人给的建议换用virtualbox,虽然virtualbo ...

  8. TortoiseSVN期望文件系统格式在“1”到“6”之间;发现格式“7”

    安装好Subversion和TortoiseSVN之后.检出和浏览版本库的时候一直报错 "期望文件系统格式在"1"到"6"之间;发现格式"7 ...

  9. GLib基础

    实用功能 GLib中包含了近二十种实用功能,从简单的字符处理到初学者很难理解的XML解析功能,这里介绍两种较简单的:随机数和计时. 下面代码演示如何产生1-100之间的随机整数和演示如何计算30000 ...

  10. Botposter.com集群ETCD2.3.7升级至3.0实录[原创]

    7月1日,为庆祝我党生日,ETCD隆重发布了3.0版本.Botposter.com也在第一时间对集群进行了升级.本文是升级过程的记录与总结(文中假设读者已经使用或测试过ETCD V2,如有不妥请见谅) ...