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的两倍. ...
随机推荐
- php和js区别
php和js区别 两者在语法上类似,楼上说的对,js=javascript是工作在浏览器端的脚本语言,他所提交的数据是交给浏览器来处理的.但是现在的Ajax技术已经可以把js提交的数据交付到浏览器来处 ...
- Spark技术在京东智能供应链预测的应用——按照业务进行划分,然后利用scikit learn进行单机训练并预测
3.3 Spark在预测核心层的应用 我们使用Spark SQL和Spark RDD相结合的方式来编写程序,对于一般的数据处理,我们使用Spark的方式与其他无异,但是对于模型训练.预测这些需要调用算 ...
- Excel中将字符串中从右起第n个指定字符替换的方法
比如你想把www.baidu.com.cn中的倒数第二个”.”替换成@,则可以用: =SUBSTITUTE(A1,".","@",LEN(A1)-LEN(SUB ...
- ajax的cache缓存的使用方法
ajax中cache缓存的使用: 问题描述: 在IE.360浏览器上提交表单后,保存后的内容不回显(依然显示空或者之前的内容). 原因: 回显内容是使用ajax的get方式的请求查询数据,ajax的c ...
- springMVC接受对象实体并且对象实体里面又有对象集合方式
springMVC接受对象实体并且对象实体里面又有对象集合方式: Ajax: function add(){ var orders = [ { orderNo : "H222255" ...
- JS基本功 | JavaScript专题之数组 - 方法总结
Array.map() 1. map() 遍历数组 语法: let new_array = arr.map(function callback(currentValue, index, array ...
- ActiveMQ学习笔记(14)----Destination高级特性(二)
1. Visual Destinations 1.1 概述 虚拟Destination用来创建逻辑Destinations,客户端可以通过它来产生和消费消息,它会把消息映射到物理Destination ...
- (五)Redux入门
1 Redux概念简述 flux推出的时候有一些缺点.比如store可以存在多个,不是特别好用 于是逐渐进化为了redux. 2 Redux的工作流程 拿借书作举例: action creators是 ...
- HashMap和Hashtable的区别。
HashMap是Hashtable的轻量级实现(非线程安全的实现),他们都完成了Map接口,主要区别在于HashMap允许空(null)键值(key),由于非线程安全,效率上可能高于Hashtable ...
- Oracle with as 嵌套
oracle with as可以理解为临时视图,可以极大的简化sql语句,并且支持嵌套使用. With c3 As(Select * From v_tr_daily Where p_date=to_ ...