ACM-ICPC 2016 Qingdao Preliminary Contest
A I Count Two Three
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 iii-th attacks failed if and only if iii can be rewritten as the form of 2a3b5c7d2^a3^b5^c7^d2a3b5c7d which a, b, c, d are non-negative integers.
At recent dinner parties, we call the integers with the form 2^a3^b5^c7^d "I Count Two Three Numbers".
A related board game with a given positive integer nnn from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than nnn.
Input Format
The first line of input contains an integer t(1≤t≤500000), the number of test cases. ttt test cases follow. Each test case provides one integer 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 nnn.
样例输入
10
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
样例输出
1
12
14
125
1250
12348
123480
1234800
12348000
123480000
打表后二分查找。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
ll v[],tot=;
ll a[],b[],c[],d[];
void init()
{
a[]=b[]=c[]=d[]=;
for(int i=;i<=;i++)
a[i]=a[i-]*;
for(int i=;i<=;i++)
b[i]=b[i-]*;
for(int i=;i<=;i++)
c[i]=c[i-]*;
for(int i=;i<=;i++)
d[i]=d[i-]*;
for(int i=;i<=;i++)
{
if(a[i]>) break;
for(int j=;j<=;j++)
{
if(b[j]>) break;
for(int k=;k<=;k++)
{
if(c[k]>) break;
for(int z=;z<=;z++)
{
if(d[z]>) break;
if(a[i]*b[j]*c[k]*d[z]<=) v[tot++]=a[i]*b[j]*c[k]*d[z];
else break;
}
}
}
}
sort(v,v+tot);
}
int main()
{
ll n,t;
scanf("%d",&t);
init();
while(t--)
{
scanf("%lld",&n);
int k=lower_bound(v,v+tot,n)-v;
printf("%lld\n",v[k]);
}
return ;
}
B Cure
Given an integer nnn, we only want to know the sum of 1/k2 where k from 1 to n.
Input Format
There are multiple cases.
For each test case, there is a single line, containing a single positive integer nnn.
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
保留5位小数,当k值足够大时,恒等于0
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
ll n;
double ans[];
string s;
int main()
{
ans[]=0.0;
for(ll i=;i<=;i++)
ans[i]=ans[i-]+1.0/(i*i);
while(cin>>s)
{
if(s.size()>) printf("%.5lf\n",ans[]);
else
{
int n=;
for(int i=;i<s.size();i++)
n=n*+(s[i]-'');
if(n>) printf("%.5lf\n",ans[]);
else printf("%.5lf\n",ans[n]);
}
}
return ;
}
D Tea
Tea is good.
Tea is life.
Tea is everything.
The balance of tea is a journey of pursuing balance of the universe.
Alice knows that.
Alice wants to teach you the art of pouring tea.
Alice has a pot of tea.
The exact volume of tea is not important.
The exact volume of tea is at least LLL.
The exact volume of tea is at most RRR.
Alice put two empty cups between you and her.
Alice wants the two cups filled by almost equal volume of tea.
Yours cannot be 1 unit more than hers.
Hers cannot be 1 unit more than yours.
Alice wants you to pour the tea.
Alice wants you to pour until the pot is almost empty.
Alice wants no more than 1 unit volume of tea remaining in the pot.
You cannot read the residue volume of tea remaining in the pot.
You can only know the tea status in the pot, empty or not.
Alice does not want you to pour the tea too many times.
You better pour as few times as possible.
Input Format
There are multiple cases.
For each case, there is one line of two integers L and R, separated by single space.
Here are some analyses about sample cases.
For the first case, pouring 1 unit into one cup will satisfy Alice.
For the second case, it is clearly that you cannot only pour once to reach the desired balance, but she can achieve it by pouring twice.
First you pour 1.5 units into one cup, then you attempt to pour another 1.5 units into the other cup.
Since the lower bound is 2, at least 0.5 unit remains in the pot after the first pouring.
If the initial volume is in range [2, 3], the second cup will have volume in range [0.5, 1.5] which is balanced with 1.51.51.5 unit in the first cup, and at most 111 unit remain after these two attempts.
About 1000 test cases, and 0≤L≤R≤1016.
Output Format
For each case, there should be a single integer in a single line, the least number of pouring attempts.
样例输入
2 2
2 4
样例输出
1
2
题目很长读了很久,但就是使得分配完后,两个杯子内茶水的体积相差不超过一,茶壶内剩余不超过一,问最少倒几次
首先确定下界,这是茶壶里一定存在的可以平分,下界到上界不确定的,只能按部就班分
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
ll l,r;
int main()
{
while(~scanf("%lld%lld",&l,&r))
{
if(r<=) printf("0\n");
else if(r<=) printf("1\n");
else if(l==r || l==r-) printf("2\n");
else if(r>l+)
{
if(l==) l=;
printf("%lld\n",(r-l)/+);
}
}
return ;
}
E Balanced Game
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\%50% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer NNN, 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 ttt, the number of test cases. ttt test cases follow.
For each test case, there is only one line with an integer 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
题目很长,刚开始猜小于等于是balanced,否则是bad。wa了。
仔细一分析,只要是偶数我只取可以互相抵消的一定可以打平,分奇偶。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
int main()
{
int t,n;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
puts(n&?"Balanced":"Bad");
}
return ;
}
F The Best Path
Alice is planning her travel route in a beautiful valley. In this valley, there are NNN lakes, and MMM rivers linking these lakes. Alice wants to start her trip from one lake, and enjoys the landscape by boat. That means she need to set up a path which go through every river exactly once. In addition, Alice has a specific number (a1, a2, ..., an) for each lake. If the path she finds is P0→P1→...→Pt, the lucky number of this trip would be aP0xor aP1 xor ... xor aPt. She want to make this number as large as possible. Can you help her?
Input Format
The first line of input contains an integer ttt, the number of test cases. ttt test cases follow.
For each test case, in the first line there are two positive integers N(N≤100000) and M(M≤500000), as described above. The iii-th line of the next NNN lines contains an integer ai(∀i, 0≤ai≤10000) representing the number of the i-th lake.
The i-th line of the next M lines contains two integers ui and vi representing the iii-th river between the uith lake and vith lake. It is possible that ui=vi.
Output Format
For each test cases, output the largest lucky number. If it dose not have any path, output "Impossible".
样例输入
2
3 2
3
4
5
1 2
2 3
4 3
1
2
3
4
1 2
2 3
2 4
样例输出
2
Impossible
考欧拉路径的性质,自己写的max函数不能用,无限wa,还得用库函数
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
//#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
const int maxn=;
int a[maxn],n,m,t,de[maxn];
int solve()
{
int pos=,ans=;
for(int i=;i<=n;i++)
{
if(de[i]&)
pos++;
}
if(pos!= && pos!=)
return -;
for(int i=;i<=n;i++)
{
de[i]=(de[i]+)/;
if(de[i]&)
ans^=a[i];
}
if(pos==)
{
for(int i=;i<=n;i++)
ans=max(ans,ans^a[i]);
}
return ans;
}
int main()
{
scanf("%d",&t);
while(t--)
{
memset(de,,sizeof(de));
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
de[x]++;de[y]++;
}
int ans=solve();
if(ans== -) printf("Impossible\n");
else printf("%d\n",ans);
}
return ;
}
G Sort
Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from Alice.
Alice will give Bob NNN sorted sequences, and the iii-th sequence includes ai elements. Bob need to merge all of these sequences. He can write a program, which can merge no more than kkk sequences in one time. The cost of a merging operation is the sum of the length of these sequences. Unfortunately, Alice allows this program to use no more than T cost. So Bob wants to know the smallest kkk to make the program complete in time.
Input Format
The first line of input contains an integer t0, the number of test cases. t0t_0t0 test cases follow.
For each test case, the first line consists two integers N(2≤N≤100000) and T(∑i=1Nai<T<231).
In the next line there are NNN integers a1, a2, a3, ..., aN(∀i, 0≤ai≤1000).
Output Format
For each test cases, output the smallest kkk.
样例输入
1
5 25
1 2 3 4 5
样例输出
3
二分+优先队列
想到了二分,也想到了最后不够k个序列的单独处理,但就是没想到不够k个的应该最先处理,将小的累加,结果会更小
wa了好几次。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <ctime>
#include <map>
#include <set>
using namespace std;
#pragma comment(linker, "/stck:1024000000,1024000000")
#pragma GCC diagnostic error "-std=c++11"
#define lowbit(x) (x&(-x))
#define max(x,y) (x>=y?x:y)
#define min(x,y) (x<=y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define esp 1e-9
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.1415926535897932384626433832
#define ios() ios::sync_with_stdio(true)
#define INF 0x3f3f3f3f
typedef long long ll;
int t,n,k,a[],ans[];
int solve(int m)
{
priority_queue<int,vector<int>,greater<int> >q;
int mid=(n-)%(m-),sum=,cnt=,pos=;
if(mid){
mid++;
cnt+=ans[mid];
q.push(cnt);
}
for(int i=mid+;i<=n;i++)
q.push(a[i]);
while()
{
sum+=q.top();
q.pop();
pos++;
if(pos==m){
cnt+=sum;
if(cnt>k) return ;
if(q.size()==){
break;
}
q.push(sum);
sum=;
pos=;
}
}
if(cnt>k) return ;
return ;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
sort(a+,a++n);
for(int i=;i<=n;i++)
ans[i]=ans[i-]+a[i];
int l=,r=n;
while(l<r)
{
int mid=l+r>>;
if(solve(mid)) l=mid+;
else r=mid;
}
printf("%d\n",r);
}
return ;
}
ACM-ICPC 2016 Qingdao Preliminary Contest的更多相关文章
- ACM-ICPC 2016 Qingdao Preliminary Contest G. Sort
Recently, Bob has just learnt a naive sorting algorithm: merge sort. Now, Bob receives a task from A ...
- ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s Rect ...
- ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016
题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...
- [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题
第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...
- Samara SAU ACM ICPC 2013-2014 Quarterfinal Qualification Contest
A: 简单题,因为题目中说了不会有数据相同: #include<cstdio> #include<algorithm> #define maxn 200005 using na ...
- 最小割 D. Behind the Wall Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest
题目链接:http://codeforces.com/gym/101149/problem/D 题目大意: 堡垒受到攻击.堡垒是n*m的矩阵,矩阵里刚开始都是平地,然后那个数值表示在当前平地上建一面墙 ...
- ACM ICPC, JUST Collegiate Programming Contest (2018) Solution
A:Zero Array 题意:两种操作, 1 p v 将第p个位置的值改成v 2 查询最少的操作数使得所有数都变为0 操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...
- ACM ICPC, Amman Collegiate Programming Contest (2018) Solution
Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...
- 几何+思维 Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest K. Revenge of the Dragon
题目链接:http://codeforces.com/gym/101149/problem/K 题目大意: 给你两个点a,b.一个人在a点,一个人在b点,b点的人要追杀a的点,他的跑步速度是a的两倍. ...
随机推荐
- Get Client IP
How to get a user's client IP address in ASP.NET? Often you will want to know the IP address of some ...
- nyoj--891--找点(贪心)
找点 时间限制:2000 ms | 内存限制:65535 KB 难度:2 描述 上数学课时,老师给了LYH一些闭区间,让他取尽量少的点,使得每个闭区间内至少有一个点.但是这几天LYH太忙了,你们帮 ...
- CxImage 简单配置与使用
CxImage 简单配置与使用 如果本篇文章还不能解决你在生成解决方案以及便宜过程中的问题 请参阅: http://blog.csdn.net/afterwards_/article/details/ ...
- DB-MySQL:MySQL 函数
ylbtech-DB-MySQL:MySQL 函数 1. MySQL 字符串函数返回顶部 1. MySQL 字符串函数 函数 描述 实例 ASCII(s) 返回字符串 s 的第一个字符的 ASCII ...
- 50.AngularJs directive详解及示例代码
转自:https://www.cnblogs.com/best/tag/Angular/ 本教程使用AngularJs版本:1.5.3 AngularJs GitHub: https://github ...
- Kettle的四大不同环境工具
不多说,直接上干货! kettle里有不同工具,分别用于ETL的不同阶段. 初学者,建议送Spoon开始.高手,是四大工具都会用. Sqoop: 图形界面工具,快速设计和维护复杂的ETL工作流.集成开 ...
- (转载)Android:学习AIDL,这一篇文章就够了(下)
前言 上一篇博文介绍了关于AIDL是什么,为什么我们需要AIDL,AIDL的语法以及如何使用AIDL等方面的知识,这一篇博文将顺着上一篇的思路往下走,接着介绍关于AIDL的一些更加深入的知识.强烈建议 ...
- Servlet学习(七)——cookie
一.会话技术简介 1.存储客户端的状态 例如网站的购物系统,用户将购买的商品信息存储到哪里?因为Http协议是无状态的,也就是说每个客户访问服务器端资源时,服务器并不知道该客户端是谁,所以需要会话技术 ...
- 1112 KGold
给出N个人在0时刻的财富值M[i](所有人在0时刻的财富互不相等),以及财富增长速度S[i],随着时间的推移,某些人的财富值会超越另外一些人.如果时间足够长,对于财富增长最快的人来说,他的财富将超越所 ...
- javascript 异或运算符实现简单的密码加密功能
写在前面的 当我们需要在数据库中存储用户的密码时,当然是不能明文存储的. 我们就是介绍一下用^运算符来实现简单的密码加密以及解密功能 上代码 首先,回顾一下基础知识. String.fromCharc ...