码迷,mamicode.com
首页 > 其他好文 > 详细

Ural 1971(Graphics Settings-延迟计算)

时间:2014-07-02 08:16:27      阅读:333      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   strong   width   

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行分别有指令名 si,  和整数 ki(2 ≤ ki ≤ 100),指令名为长度在[1,10]的小写字母字符串,下一行为 WH,和 p (320 ≤ W ≤ 2 560; 200 ≤ H ≤ 1 600; 1 ≤ p ≤ 109). 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 nextm 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

本题思路不难理解,问题在于∏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;
}








Ural 1971(Graphics Settings-延迟计算),布布扣,bubuko.com

Ural 1971(Graphics Settings-延迟计算)

标签:des   style   http   color   strong   width   

原文地址:http://blog.csdn.net/nike0good/article/details/36187563

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!