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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  4. [刷题]ACM/ICPC 2016北京赛站网络赛 第1题 第3题

    第一次玩ACM...有点小紧张小兴奋.这题目好难啊,只是网赛就这么难...只把最简单的两题做出来了. 题目1: 代码: //#define _ACM_ #include<iostream> ...

  5. Samara SAU ACM ICPC 2013-2014 Quarterfinal Qualification Contest

    A: 简单题,因为题目中说了不会有数据相同: #include<cstdio> #include<algorithm> #define maxn 200005 using na ...

  6. 最小割 D. Behind the Wall Samara University ACM ICPC 2016-2017 Quarterfinal Qualification Contest

    题目链接:http://codeforces.com/gym/101149/problem/D 题目大意: 堡垒受到攻击.堡垒是n*m的矩阵,矩阵里刚开始都是平地,然后那个数值表示在当前平地上建一面墙 ...

  7. ACM ICPC, JUST Collegiate Programming Contest (2018) Solution

    A:Zero Array 题意:两种操作, 1 p v  将第p个位置的值改成v  2  查询最少的操作数使得所有数都变为0  操作为可以从原序列中选一个非0的数使得所有非0的数减去它,并且所有数不能 ...

  8. ACM ICPC, Amman Collegiate Programming Contest (2018) Solution

    Solution A:Careful Thief 题意:给出n个区间,每个区间的每个位置的权值都是v,然后找长度为k的区间,使得这个区间的所有位置的权值加起来最大,输出最大权值, 所有区间不重叠 思路 ...

  9. 几何+思维 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的两倍. ...

随机推荐

  1. linux 下的两种软件安装方式 —— 源码(编译、安装),编译好的二进制(直接安装)

    我们以 GPG(加密工具)为例来说明两种安装方式的区别: 源码(Source code releases,名称中则会含有src等说明信息,tarball:source),先编译再安装 GPU 的源码地 ...

  2. Under ubuntu 12.04,install sublime text 2

    Sublime Text is an awesome text editor. If you’ve never heard of it, you should check it out right n ...

  3. 报表工具Report Builder 3.0的安装

    工作后第一次尝试独立安装一个软件啊 话不多说,总结一下过程 前言:已经Baidu了Report Builder 3.0的安装教程了,就到微软的官网上下载去了,下载完成双击程序安装告诉我,要想安装Rep ...

  4. VisualStudio UnitTest FrameWork

    当创建单元测试时,Microsoft.VisualStudio.TestTools.UnitTesting的名字控件会添加到测试项目中,该名字控件中包含很多有用的类: 断言类:在单元测试中验证条件 初 ...

  5. 05:Cave Cows 1 洞穴里的牛之一

    总时间限制:  10000ms 单个测试点时间限制:  1000ms 内存限制:  262144kB 描述 很少人知道其实奶牛非常喜欢到洞穴里面去探险.     洞窟里有N(1≤N≤100)个洞室,由 ...

  6. 浏览器输入一个url的过程,以及加载完html文件和js文件的标志

    简单理解: 当在浏览器地址栏输入一url时,浏览器会做以下几个步骤: 1.将url转化为ip地址,也就是DNS解析,(先找本地host文件中是否有对应的ip地址,如果有就直接用,没有的话,就按域名的二 ...

  7. Ubuntu系统下安装Eclipse

    第一步:查看操作系统位数. 打开终端,输入file /sbin/init 可以看到笔者Ubuntu系统为32位,读者可以使用该命令获取自己机器上的操作系统位数. 这一步是最至关重要的一步,笔者机器处理 ...

  8. JavaScript在不同环境下的全局对象

    Node.js 环境下,全局的对象是 global. 浏览器下 window === self 而不是 global,今天才发现的,我惊呆了!

  9. SQL语句调优相关方法

    SQL语句慢的原因:1,数据库表的统计信息不完整2,like查询估计不准确调优方法:1,查看表中数据的条数:2, explain analyze target_SQL;查看SQL执行计划:比较SQL总 ...

  10. 【原创】VMWare克隆或复制Linux虚拟机后无法上网的解决

    如果选择桥接,需要设置网卡通过哪个物理网卡桥接,桥接代表当前虚拟机通过本机的网卡直接连到网络中,本机网卡作为一个交换机直连.因此需要确定使用哪个网卡桥接,一般在单网卡的时候选择自动即可,多网卡时需要指 ...