Ural 1971(Graphics Settings-延迟计算)

本文介绍了一个游戏性能优化的问题,通过合理的算法避免了计算过程中出现的数值溢出问题,确保了游戏在不同设置下能保持良好的运行速度。文章详细讨论了如何使用队列来延迟特定计算步骤,以维持游戏帧率在可接受范围内。

1971. Graphics Settings

Time limit: 2.0 second
Memory limit: 64 MB
给定n个选项,m个操作,问 the image generation speed=p/(W*H*∏ki(第i个选项开启))在哪个区间。

Input

第一行为  n (0 ≤  n ≤ 100 000). 接下来第i行分别有指令名  s i,  和整数  k i(2 ≤  k i ≤ 100),指令名为长度在[1,10]的小写字母字符串,下一行为  WH,和  p (320 ≤  W ≤ 2 560;  200 ≤  H ≤ 1 600;  1 ≤  p ≤ 10 9). They are the initial width and height of the screen in pixels and the clock rate of the GPU in cycles per second. 最初选项全开. 接下来为指令数  m  (1 ≤  m ≤ 100 000)  . 接下来  m 行有如下的指令:
  • “On s” — 开启 s;
  • “Off s” — 关闭 s;
  • “Resolution w h” — set the screen resolution to w × h pixels (320 ≤ w ≤ 2 560; 200 ≤ h≤ 1 600).
保证选项只在开启时关闭,只在关闭时开启.

Output

The first line should describe the performance of the game before changes in the settings. Then next m lines should describe the performance of the game after each change in the settings. Output “Slideshow” if the image generation speed is less than 10 frames per second, “Perfect” if it is 60 frames per second or greater, and “So-so” otherwise.

Sample

input output
1
vsync 10
640 480 10000000
2
Off vsync
Resolution 320 240
Slideshow
So-so
Perfect
Problem Author: Denis Dublennykh
Problem Source: Ural Sport Programming Championship 2013
Tags: none   (
hide tags for unsolved problems
)

本题思路不难理解,问题在于∏ki(第i个选项开启)会溢出

所以我们用队列存储,延迟它的计算,防止溢出


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<iostream>
#include<cmath>
#include<cctype>
#include<ctime>
#include<map>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define Lson (x<<1)
#define Rson ((x<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define MAXN (100000+10)
#define MAXKi (100+10)
#define MAXLen (10+10)
#define MAXW (2560+10)
#define MAXH (1600+10)
#define MINW (320+10)
#define MINH (200+10)
#define MAXP (1000000000)
#define MAXM (100000+10)
long long mul(long long a,long long b){return (a*b)%F;}
long long add(long long a,long long b){return (a+b)%F;}
long long sub(long long a,long long b){return (a-b+(a-b)/F*F+F)%F;}
typedef long long ll;
map<string,int> h;
int n,m,val[MAXN],q[MAXM],head=1,tail=0;
bool inq[MAXM]={0};
ll W,H,p,res=1; //res表示当前∏k
//题意:image generation speed(v)=p/res/W/H<10 / >=60 => res*W*H*10>p res*W*H*60<=p 
void print()
{
	while (res*W*H*10<=p&&head<=tail)
	{
		int now=q[head++];
		if (!inq[now]) continue;
		inq[now]=0;res*=val[now];
	}
	if (p<res*W*H*10) printf("Slideshow\n");
	else if (p<res*W*H*60) printf("So-so\n");
	else printf("Perfect\n");
	
}
int main()
{
//	freopen("ural1971.in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	For(i,n)
	{
		string s;
		cin>>s>>val[i];
		h[s]=i;
		q[++tail]=i;inq[i]=1;
	}
	cin>>W>>H>>p;
	cin>>m;
	
	print();
	For(i,m)
	{
		char s[20];
		scanf("%s",s);
		switch (s[1])
		{
			case'n':
				{
					string s;
					cin>>s;
					int p=h[s];
					inq[p]=1;q[++tail]=p;
					break;
				}
			case'f':
				{
					string s;
					cin>>s;
					int p=h[s];
					if (inq[p]) inq[p]=0;
					else res/=val[p];
					break;
				}
			default:
				{
					cin>>W>>H;
				}
		}
		print();
	}
	
	return 0;
}








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值