URAL 1971 Graphics Settings 取对数(高精度易超时)
2014-09-03 12:00
232 查看
题目大意:
现在给出一个游戏中的n个设置 n <= 10^5; 每个设置对应一个k值, k <= 100
初始的时候的分辨率为w*h
CPU的cycles为p
接下来是m次操作分别代表更改的设置
On 表示打开设置XX, Off是关闭设置XX, Revolution w,h 为更改分辨率至w*h
当前的开启的所有设置对应的k值的乘积乘上分辨率w*h得到一个数A
当 p / A < 10时输出Slideshow
p / A >= 60时输出Perfect
其他情况输出So-so
初始时所有设置都是开着的
大致思路:
刚开始的时候直接就上了java的高精度就TLE了....真是没考虑就直接上了..
后来改用了求对数的方法,虽然存在精度误差但是还是能过的
java 高精度TLE代码 ( 祭奠我冲动的TLE =_= )
Result : Time Limit Exceeded
import java.math.BigInteger;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
public class Main{
public static void main(String args[]){
int n;
BigInteger det = BigInteger.valueOf(1);
Scanner cin = new Scanner(System.in);
Map<String,Integer> map = new HashMap<String,Integer>();
n = cin.nextInt();
BigInteger p,x,y;
String tmp;
int t;
for(int i = 1; i <= n; i++)
{
tmp = cin.next();
t = cin.nextInt();
map.put(tmp, t);
det = det.multiply(BigInteger.valueOf(t));
}
x = cin.nextBigInteger();
y = cin.nextBigInteger();
p = cin.nextBigInteger();
// System.out.println(x + " " + y + " " + p);
if(p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.TEN)) == -1)
{
System.out.println("Slideshow");
}
else
{
if( p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.valueOf(60))) == -1)
{
System.out.println("So-so");
}
else
{
System.out.println("Perfect");
}
}
int m;
m = cin.nextInt();
String w;
for(int i = 1; i <= m; i++)
{
w = cin.next();
//System.out.println(w + "???");
if(w.equals("Off"))
{
tmp = cin.next();
//System.out.println(tmp);
det = det.divide(BigInteger.valueOf(map.get(tmp)));
}
else
{
if(w.equals("On"))
{
tmp = cin.next();
det = det.multiply(BigInteger.valueOf(map.get(tmp)));
}
else
{
x = cin.nextBigInteger();
y = cin.nextBigInteger();
}
}
if(p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.TEN)) == -1)
{
System.out.println("Slideshow");
}
else
{
if( p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.valueOf(60))) == -1)
{
System.out.println("So-so");
}
else
{
System.out.println("Perfect");
}
}
}
}
}
取对数的做法:
Result : Accepted Memory : 10973 KB Time : 1671 ms
/*
* Author: Gatevin
* Created Time: 2014/8/31 13:53:44
* File Name: A.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
map<string, int> M;
int a[100010];
int n,m;
string tmp1;
string tmp2;
int w,h,p;
int main()
{
cin>>n;
int k;
for(int i = 1; i <= n; i++)
{
cin>>tmp1>>a[i];
M[tmp1] = a[i];
}
cin>>w>>h>>p;
k = w*h;
double pp = log(p*1.0);
double hh = 0;
hh += log(k*1.0);
for(int i = 1; i <= n; i++)
{
hh += log(a[i]*1.0);
}
if(pp < log(10.0) + hh)
{
printf("Slideshow\n");
}
else
{
if(pp < log(60.0) + hh)
{
printf("So-so\n");
}
else
{
printf("Perfect\n");
}
}
cin>>m;
while(m--)
{
cin>>tmp1;
if(tmp1 == "Off")
{
cin>>tmp2;
hh -= log(M[tmp2]*1.0);
}
else
{
if(tmp1 == "On")
{
cin>>tmp2;
hh += log(M[tmp2]*1.0);
}
else
{
cin>>w>>h;
hh -= log(k*1.0);
hh += log(w*h*1.0);
k = w*h;
}
}
if(pp < log(10.0) + hh)
{
printf("Slideshow\n");
}
else
{
if(pp < log(60.0) + hh)
{
printf("So-so\n");
}
else
{
printf("Perfect\n");
}
}
}
return 0;
}
现在给出一个游戏中的n个设置 n <= 10^5; 每个设置对应一个k值, k <= 100
初始的时候的分辨率为w*h
CPU的cycles为p
接下来是m次操作分别代表更改的设置
On 表示打开设置XX, Off是关闭设置XX, Revolution w,h 为更改分辨率至w*h
当前的开启的所有设置对应的k值的乘积乘上分辨率w*h得到一个数A
当 p / A < 10时输出Slideshow
p / A >= 60时输出Perfect
其他情况输出So-so
初始时所有设置都是开着的
大致思路:
刚开始的时候直接就上了java的高精度就TLE了....真是没考虑就直接上了..
后来改用了求对数的方法,虽然存在精度误差但是还是能过的
java 高精度TLE代码 ( 祭奠我冲动的TLE =_= )
Result : Time Limit Exceeded
import java.math.BigInteger;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;
public class Main{
public static void main(String args[]){
int n;
BigInteger det = BigInteger.valueOf(1);
Scanner cin = new Scanner(System.in);
Map<String,Integer> map = new HashMap<String,Integer>();
n = cin.nextInt();
BigInteger p,x,y;
String tmp;
int t;
for(int i = 1; i <= n; i++)
{
tmp = cin.next();
t = cin.nextInt();
map.put(tmp, t);
det = det.multiply(BigInteger.valueOf(t));
}
x = cin.nextBigInteger();
y = cin.nextBigInteger();
p = cin.nextBigInteger();
// System.out.println(x + " " + y + " " + p);
if(p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.TEN)) == -1)
{
System.out.println("Slideshow");
}
else
{
if( p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.valueOf(60))) == -1)
{
System.out.println("So-so");
}
else
{
System.out.println("Perfect");
}
}
int m;
m = cin.nextInt();
String w;
for(int i = 1; i <= m; i++)
{
w = cin.next();
//System.out.println(w + "???");
if(w.equals("Off"))
{
tmp = cin.next();
//System.out.println(tmp);
det = det.divide(BigInteger.valueOf(map.get(tmp)));
}
else
{
if(w.equals("On"))
{
tmp = cin.next();
det = det.multiply(BigInteger.valueOf(map.get(tmp)));
}
else
{
x = cin.nextBigInteger();
y = cin.nextBigInteger();
}
}
if(p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.TEN)) == -1)
{
System.out.println("Slideshow");
}
else
{
if( p.compareTo(x.multiply(y).multiply(det).multiply(BigInteger.valueOf(60))) == -1)
{
System.out.println("So-so");
}
else
{
System.out.println("Perfect");
}
}
}
}
}
取对数的做法:
Result : Accepted Memory : 10973 KB Time : 1671 ms
/*
* Author: Gatevin
* Created Time: 2014/8/31 13:53:44
* File Name: A.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
map<string, int> M;
int a[100010];
int n,m;
string tmp1;
string tmp2;
int w,h,p;
int main()
{
cin>>n;
int k;
for(int i = 1; i <= n; i++)
{
cin>>tmp1>>a[i];
M[tmp1] = a[i];
}
cin>>w>>h>>p;
k = w*h;
double pp = log(p*1.0);
double hh = 0;
hh += log(k*1.0);
for(int i = 1; i <= n; i++)
{
hh += log(a[i]*1.0);
}
if(pp < log(10.0) + hh)
{
printf("Slideshow\n");
}
else
{
if(pp < log(60.0) + hh)
{
printf("So-so\n");
}
else
{
printf("Perfect\n");
}
}
cin>>m;
while(m--)
{
cin>>tmp1;
if(tmp1 == "Off")
{
cin>>tmp2;
hh -= log(M[tmp2]*1.0);
}
else
{
if(tmp1 == "On")
{
cin>>tmp2;
hh += log(M[tmp2]*1.0);
}
else
{
cin>>w>>h;
hh -= log(k*1.0);
hh += log(w*h*1.0);
k = w*h;
}
}
if(pp < log(10.0) + hh)
{
printf("Slideshow\n");
}
else
{
if(pp < log(60.0) + hh)
{
printf("So-so\n");
}
else
{
printf("Perfect\n");
}
}
}
return 0;
}
相关文章推荐
- 【BZOJ2786】【Ural1142】Relation 递推,动态规划,高精度,Python
- Ural 1012. K-based Numbers. Version 2 &&1013. K-based Numbers. Version 3 DP+高精度
- Ural_1036. Lucky Tickets(DP + 高精度)
- URAL 1036(dp+高精度)
- URAL 1108. Heritage 高精度大数乘法
- URAL1036——DP+高精度—— Lucky Tickets
- URAL 1012 K-based Numbers. Version 2(DP+高精度)
- ural 1009. K-based Numbers dp 高精度
- Ural 1971(Graphics Settings-延迟计算)
- POJ 2602|URAL 1048|Superlong Sums|高精度加法
- 2786: Ural1142 Relation (递推+高精度)
- URAL 1036 Lucky Tickets 【dp】【高精度】
- Ural_1013. K-based Numbers. Version 3(dp + 高精度)
- URAL 1009|URAL 1012|URAL 1013|K-based Numbers|高精度|动态规划
- URAL - 1012 DP+高精度
- URAL 1036 Lucky Tickets (高精度,数位dp)
- URAL - 1013 DP+高精度+滚动数组
- ACM k进制高精度优化 URAL 1803 The Czechs' Rifles 滚动数组
- DP+高精度 URAL 1036 Lucky Tickets
- 【codevs1087&&NOIP2003】麦森数,高精度+对数+快速幂