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. ES索引模板——就是在新建索引时候指定的正则匹配来设置mapping而已,对于自动扩容有用

    索引模板 扩容设计 » 索引模板 Elasticsearch 不要求你在使用一个索引前创建它. 对于日志记录类应用,依赖于自动创建索引比手动创建要更加方便. Logstash 使用事件中的时间戳来生成 ...

  2. SaltStack介绍——SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流

    SaltStack介绍和架构解析 简介 SaltStack是一种新的基础设施管理方法开发软件,简单易部署,可伸缩的足以管理成千上万的服务器,和足够快的速度控制,与他们交流,以毫秒为单位.SaltSta ...

  3. correct ways to define variables in python

    http://stackoverflow.com/questions/9056957/correct-way-to-define-class-variables-in-python later say ...

  4. Java8内置的四大核心函数式接口

    package java_8; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import j ...

  5. JavaScript学习——使用JS完成页面定时弹出广告

    1.获取图片的位置(document.getElementById(“”))  隐藏图片:display:none 定时操作:setInterval(“显示图片的函数”,3000); 2.步骤分析 ( ...

  6. (Spring+IBatis+Struts1+Struts2+Hibernate+Java EE+Oracle)

    原文出处:http://space.itpub.net/6517/viewspace-609654 1.Spring架构图 Spring是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的 ...

  7. 《鸟哥的Linux私房菜》笔记——01. 计算机概论

    计算机的五大部分:输入单元.输出单元.CPU(控制单元(Control Unit).算数逻辑单元(ALU)).内存. CPU 的架构 精简指令集(Reduced Instruction Set Com ...

  8. PIC kit3问题

    1.通过pic kit3烧录pic16F1938的时候,pic kit3自动更新了firmware,但是仍然烧录不了pic16F1938,然后再次用pic kit3烧录pic18F45k80时,一直显 ...

  9. LCD中如何描绘点阵数据

    下载软件“液晶汉字点阵zimo21” 描绘数据 打开软件后,新建图像-取模方式选择C51(A51和C51区别就是,A-F开头要加0,例如0x0AF)-模拟动画中放大格点-描绘图像-点阵生成区 对获得数 ...

  10. 马云谈AI:未来10-15年传统制造业的痛苦将远超今天的想象

    马云谈AI:未来10-15年传统制造业的痛苦将远超今天的想象 “未来10到15年,传统制造业面临的痛苦将会远远超过今天的想象,企业如果不能从规模化.标准化向个性化和智慧化转型,将很难生存下去.” 9月 ...