ACM-ICPC 2016 Qingdao Preliminary Contest
I will show you the most popular board game in the Shanghai Ingress Resistance Team.
It all started several months ago.
We found out the home address of the enlightened agent Icount2three and decided to draw him out.
Millions of missiles were detonated, but some of them failed.
After the event, we analysed the laws of failed attacks.
It's interesting that the ii-th attacks failed if and only if ii can be rewritten as the form of 2^a3^b5^c7^d2a3b5c7d which a,\ b,\ c,\ da, b, c, dare non-negative integers.
At recent dinner parties, we call the integers with the form 2^a3^b5^c7^d2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer nn from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than nn.
Input Format
The first line of input contains an integer t (1\le t \le 500000)t(1≤t≤500000), the number of test cases. tt test cases follow. Each test case provides one integer n (1\le n\le 10^9)n(1≤n≤109).
Output Format
For each test case, output one line with only one integer corresponding to the shortest "I Count Two Three Number" no smaller than nn.
样例输入
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
样例输出
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
题目来源
ACM-ICPC 2016 Qingdao Preliminary Contest
题意:
输出大于n但是是大于n中那些元素的最小的值 : 二分中最大化最小值
这些数字是由 2^a3^b5^c7^d 组成的
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<set>
#include<math.h>
using namespace std;
const int maxn=1e9;
const int mm=1e6+10;
int a[4]={2,3,5,7};
int num[mm];
int p;
int t;
int n;
void dfs(int res,long long int c)
{
if(res==4)
{
num[p++]=c;
return ;
}
while(c<=maxn)
{
num[p++]=c;
dfs(res+1,c);
c=c*a[res];
}
}
int main()
{
p=0;
dfs(0,1);
sort(num,num+p);
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
printf("%d\n",*lower_bound(num,num+p,n));
}
}
注意:
1.注意while(c<=maxn),等于号不要忘记
-
B. Cure 题库链接
- 通过率: 84.29 %
- 通过人数: 118
Given an integer nn, we only want to know the sum of 1/k^21/k2 where kk from 11 to nn.
Input Format
There are multiple cases.
For each test case, there is a single line, containing a single positive integer nn.
The input file is at most 1M.
Output Format
The required sum, rounded to the fifth digits after the decimal point.
样例输入
1
2
4
8
15
样例输出
1.00000
1.25000
1.42361
1.52742
1.58044
题目来源
ACM-ICPC 2016 Qingdao Preliminary Contest
打表,把数据存在数组里。
数据超过1e6时,数据就收敛到1.64493,所以就直接输出即可。
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
//注意这一句话:The input file is at most 1M.
//数据有可能会很大
const int maxn=2e6+10;
char s[maxn];
long long int a;
double sum;
double b[maxn];
void solve()
{
b[0]=0.0;
for(long long int i=1;i<=maxn;i++)
{
b[i]=b[i-1]+1.0/(i*i*1.0);
}
}
int main()
{
solve();
while(scanf("%s",s)!=EOF)
{
sum=0.0;
a=0;
int len=strlen(s);
if(len>6)
{
puts("1.64493");
continue;
}
for(int i=0;i<len;i++)
{
a=a*10+(s[i]-'0');
}
/*if(a>=52447)
{
puts("1.64492");
continue;
}else */
printf("%.5lf\n",b[a]);
memset(s,0,sizeof(s));
}
return 0;
}
超时::
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
//注意这一句话:The input file is at most 1M.
//数据有可能会很大
const int maxn=34580;
char s[maxn];
long long int a;
double sum;
double b[maxn];
int main()
{
while(scanf("%s",s)!=EOF)
{
sum=0.0;
a=0;
int len=strlen(s);
if(len>=7)
{
puts("1.64993");
continue;
}
for(int i=0;i<len;i++)
a=a*10+(s[i]-'0');
while(a)
{
sum=sum+1.0/(a*a*1.0);
a--;
}
printf("%.5lf\n",sum);
}
return 0;
}
注意:
1.由于输入是《The input file is at most 1M.》,所以输入可以是无限大,因此用字符串来存储输入的数据。
2.直接用普通方法做会超时,因为数据当超过1e6之后,数据就不再变化,收敛到1.64493,所以就不用每次都去循环一遍,直接把数据存起来,当用到的时候直接输出就好了。
3.用到打表的知识。
-
C. Family View 题库链接
- 通过率: 59.26 %
- 通过人数: 16
-
D. Tea 题库链接
- 通过率: 90 %
- 通过人数: 63
-
E. Balanced Game 题库链接
- 通过率: 96.64 %
- 通过人数: 144
Rock-paper-scissors is a zero-sum hand game usually played between two people, in which each player simultaneously forms one of three shapes with an outstretched hand. These shapes are "rock", "paper", and "scissors". The game has only three possible outcomes other than a tie: a player who decides to play rock will beat another player who has chosen scissors ("rock crushes scissors") but will lose to one who has played paper ("paper covers rock"); a play of paper will lose to a play of scissors ("scissors cut paper"). If both players choose the same shape, the game is tied and is usually immediately replayed to break the tie.
Recently, there is a upgraded edition of this game: rock-paper-scissors-Spock-lizard, in which there are totally five shapes. The rule is simple: scissors cuts paper; paper covers rock; rock crushes lizard; lizard poisons Spock; Spock smashes scissors; scissors decapitates lizard; lizard eats paper; paper disproves Spock; Spock vaporizes rock; and as it always has, rock crushes scissors.
Both rock-paper-scissors and rock-paper-scissors-Spock-lizard are balanced games. Because there does not exist a strategy which is better than another. In other words, if one chooses shapes randomly, the possibility he or she wins is exactly 50\%50% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer NN, representing the count of shapes in a game. You need to find out if there exist a rule to make this game balanced.
Input Format
The first line of input contains an integer tt, the number of test cases. tt test cases follow.
For each test case, there is only one line with an integer N (2\le N\le 1000)N(2≤N≤1000), as described above.
Here is the sample explanation.
In the first case, donate two shapes as A and B. There are only two kind of rules: A defeats B, or B defeats A. Obviously, in both situation, one shapes is better than another. Consequently, this game is not balanced.
In the second case, donate two shapes as A, B and C. If A defeats B, B defeats C, and C defeats A, this game is balanced. This is also the same as rock-paper-scissors.
In the third case, it is easy to set a rule according to that of rock-paper-scissors-Spock-lizard.
Output Format
For each test cases, output "Balanced" if there exist a rule to make the game balanced, otherwise output "Bad".
样例输入
3
2
3
5
样例输出
Bad
Balanced
Balanced
题目来源
ACM-ICPC 2016 Qingdao Preliminary Contest
当输入是偶数时,就输出Bad,当输入是奇数时,就输出Balanced
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
using namespace std;
int main()
{
int t,r;
scanf("%d",&t);
for(int i=0;i<t;i++)
{
scanf("%d",&r);
if(r%2==0)
{
puts("Bad");
}
else
{
puts("Balanced");
}
}
return 0;
}
-
F. The Best Path 题库链接
- 通过率: 83.67 %
- 通过人数: 41
-
G. Sort 题库链接
- 通过率: 51.85 %
- 通过人数: 28
-
H. XM Reserves 题库链接
- 通过率: 50 %
- 通过人数: 1
-
I. Tower Defence 题库链接
- 通过率: 0 %
- 通过人数: 0
-
J. Herbs Gathering 题库链接
- 通过率: 58.62 %
- 通过人数: 17
-
K. Barricade 题库链接
- 通过率: 25 %
- 通过人数: 1
-
L. Eighty seven 题库链接
- 通过率: 42.86 %
- 通过人数: 3
-
M. String 题库链接
- 通过率: 0 %
- 通过人数: 0