2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)
2016 ACM/ICPC Asia Regional Qingdao Online(部分题解)
5878---I Count Two Three http://acm.hdu.edu.cn/showproblem.php?pid=5878
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1287 Accepted Submission(s): 604
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 i-th attacks failed if and only if i can be rewritten as the form of 2a3b5c7d which a,b,c,d are non-negative integers.
At recent dinner parties, we call the integers with the form 2a3b5c7d "I Count Two Three Numbers".
A related board game with a given positive integer n from one agent, asks all participants the smallest "I Count Two Three Number" no smaller than n.
1
11
13
123
1234
12345
123456
1234567
12345678
123456789
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std; int t,n,cnt;
long long st[500005],p,r;
long long p2[500005],p3[500005],p5[500005],p7[500005]; int main()
{
scanf("%d",&t);
r=1;
p2[0]=r;
for(int i=1;i;i++)
{
if(r>1e9)break;
r*=2;
p2[i]=r;
}
r=1;
p3[0]=r;
for(int i=1;i;i++)
{
if(r>1e9)break;
r*=3;
p3[i]=r;
}
r=1;
p5[0]=r;
for(int i=1;i;i++)
{
if(r>1e9)break;
r*=5;
p5[i]=r;
}
r=1;
p7[0]=r;
for(int i=1;i;i++)
{
if(r>1e9)break;
r*=7;
p7[i]=r;
}
cnt=0;
for(int i=0;i<=31;i++)
{
for(int j=0;j<=19;j++)
{
for(int k=0;k<=12;k++)
{
for(int v=0;v<=11;v++)
{
p=p2[i]*p3[j];
if(p>1e9)break;
st[++cnt]=p;
if(p<1e9)
{
p*=p5[k];
if(p>1e9)break;
st[++cnt]=p;
}
else break;
if(p<1e9)
{
p*=p7[v];
if(p>1e9)break;
st[++cnt]=p;
}
}
}
}
}
sort(st+1,st+cnt+1);
while(t--)
{
scanf("%d",&n);
printf("%lld\n",*lower_bound(st+1,st+cnt+1,n));
}
return 0;
}
5879---Cure http://acm.hdu.edu.cn/showproblem.php?pid=5879
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1783 Accepted Submission(s): 568
For each test case, there is a single line, containing a single positive integer n.
The input file is at most 1M.
2
4
8
15
1.25000
1.42361
1.52742
1.58044
这题可以找规律发现到某一点往上至正无穷大,数值都不会变,然后就好做啦~只需要处理前几十万个。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std; string n;
long double sum[400005]; int main()
{
sum[0]=(long double)0.0;
for(int i=1;i<=400000;i++)
{
sum[i]=sum[i-1]+(long double)1.0/(long double)i/(long double)i;
}
while(cin>>n)
{
if(n[0]=='-')n[0]='0';
long long p=0;
bool f=0;
for(int i=0;i<n.size();i++)
{
p=p*10+n[i]-48;
if(p>400000)
{
printf("%.5f\n",(double)sum[400000]);
f=1;
break;
}
}
if(f==0)
{
printf("%.5f\n",(double)sum[p]);
}
}
return 0;
}
5882---Balanced Game http://acm.hdu.edu.cn/showproblem.php?pid=5882
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 435 Accepted Submission(s): 377
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% no matter how the other one plays (if there is a tie, repeat this game until someone wins). Given an integer N, representing the count of shapes in a game. You need to find out if there exist a rule to make this game balanced.
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.
2
3
5
Balanced
Balanced
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
using namespace std; int t,n;
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
if(n%2==0)cout<<"Bad"<<endl; else cout<<"Balanced"<<endl;
}
return 0;
}
5883---The Best Pathhttp://acm.hdu.edu.cn/showproblem.php?pid=5883
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1155 Accepted Submission(s): 515
For each test case, in the first line there are two positive integers N (N≤100000) and M (M≤500000), as described above. The i-th line of the next N 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 i-th river between the ui-th lake and vi-th lake. It is possible that ui=vi.
3 2
3
4
5
1 2
2 3
4 3
1
2
3
4
1 2
2 3
2 4
裸的一笔画问题,判欧拉回路与欧拉通路两种与连通性。
欧拉通路没啥好说的,首尾点固定,路线固定。
欧拉回路,即环。值是不定的,要求最大,即将必须通过的点XOR,再枚举开头初始点,与之前ans进行XOR,比最值。
不是一笔画即Impossible。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<set>
using namespace std; int t,n,m,x,y,ans,p,cnt;
int a[100005],sum[100005],par[100005]; int find(int x)
{
if(x==par[x])return x; else return par[x]=find(par[x]);
} void unionx(int x,int y)
{
x=find(x);
y=find(y);
if(x==y)return ;
par[x]=y;
} int main()
{
scanf("%d",&t);
while(t--)
{
for(int i=1;i<=n;i++)par[i]=i;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
memset(sum,0,sizeof(sum));
for(int i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
unionx(x,y);
sum[x]++;
sum[y]++;
}
cnt=0;
for(int i=1;i<=n;i++)
{
if(i==par[i] && sum[i]!=0)cnt++;
}
if(cnt>1)
{
cout<<"Impossible"<<endl;
continue;
}
p=0;
ans=0;
for(int i=1;i<=n;i++)
{
if(sum[i]==0)continue;
if(sum[i]%2==1)p++;
ans^=(((sum[i]+1)/2)%2)*a[i];
}
if(p!=0 && p!=2)
{
cout<<"Impossible"<<endl;
continue;
}
if(p==2)
{
printf("%d\n",ans);
continue;
}
else
{
int anss=0;
for(int i=1;i<=n;i++)
{
if(sum[i]==0)continue;
anss=max(anss,ans^a[i]);
}
printf("%d\n",anss);
}
}
return 0;
}
先只看了几道通过率高的题A了,剩余的题如果还有A的,且心情好的话再补上。。。
毕竟之前两天辣么的题目都没挂上来。原因。。。文化课掉出年级250外了。。。
2016 ACM/ICPC Asia Regional Qingdao Online(2016ACM青岛网络赛部分题解)的更多相关文章
- 2016 ACM/ICPC Asia Regional Qingdao Online 1001/HDU5878 打表二分
I Count Two Three Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5889 Barricade 【BFS+最小割 网络流】(2016 ACM/ICPC Asia Regional Qingdao Online)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total S ...
- 【2016 ACM/ICPC Asia Regional Qingdao Online】
[ HDU 5878 ] I Count Two Three 考虑极端,1e9就是2的30次方,3的17次方,5的12次方,7的10次方. 而且,不超过1e9的乘积不过5000多个,于是预处理出来,然 ...
- hdu 5878 I Count Two Three (2016 ACM/ICPC Asia Regional Qingdao Online 1001)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5878 题目大意: 给出一个数n ,求一个数X, X>=n. X 满足一个条件 X= 2^a*3^ ...
- Hdu OJ 5884-Sort (2016 ACM/ICPC Asia Regional Qingdao Online)(二分+优化哈夫曼)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 题目大意:有n个有序的序列,对于第i个序列有ai个元素. 现在有一个程序每次能够归并k个序列, ...
- 2016 ACM/ICPC Asia Regional Qingdao Online HDU5889
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5889 解法:http://blog.csdn.net/u013532224/article/details ...
- 2016 ACM/ICPC Asia Regional Qingdao Online HDU5883
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5883 解法:先判断是不是欧拉路,然后枚举 #pragma comment(linker, "/S ...
- 2016 ACM/ICPC Asia Regional Qingdao Online HDU5882
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5882 解法:一个点必须出度和入度相同就满足题意,所以加上本身就是判断奇偶性 #include<std ...
- 2016 ACM/ICPC Asia Regional Qingdao Online HDU5879
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5879 解法:我们知道到某个极限之后结果相同,所以找到那个极限,其他保存之后输出就好了 #include&l ...
随机推荐
- 二叉树查找(C#)
参考文章: http://www.cnblogs.com/huangxincheng/archive/2012/07/21/2602375.html http://www.cnblogs.com/xi ...
- 学习Redis从这里开始
本文主要内容 Redis与其他软件的相同之处和不同之处 Redis的用法 使用Python示例代码与Redis进行简单的互动 使用Redis解决实际问题 Redis是一个远程内存数据库,它不仅性能强劲 ...
- 使用eclipse和maven一步一步配置web项目
http://www.blogjava.net/kevonz/archive/2012/07/08/382542.html
- ZOJ 3941 Kpop Music Party
先把能合并的区间都合并起来. 考虑最裸的贪心策略,从左到右一段一段的取. 但是,这样会有错,错在没有考虑每段区间选取最后一个点. 因为N只有10,所以枚举一下哪些区间最后一个点会被选择,然后按照最裸的 ...
- window.location.href 和 document.location.href
document表示的是一个文档对象,window表示的是一个窗口对象,一个窗口下可以有多个文档对象. 所以一个窗口下只有一个window.location.href,但是可能有多个document. ...
- layer 的一些知识
layer类似于ps的图层,如果把一个uiview看做图片的画,layer就像是图层.一个图片是由很多个大小不同的有层次的图层构成的,uiview也是. 1. 一个view有一个underlying ...
- mvc中上传图片到指定文件夹中
前台: @using (Html.BeginForm("AddImg", "UpFileImg", FormMethod.Post, new { enctype ...
- iOS 发布流程 分类: ios相关 app相关 2015-05-22 14:50 186人阅读 评论(0) 收藏
1.登陆苹果开发者中心http://developer.apple.com(99美元账号) 2.进入itunes connect 3.选择Manage Your Apps 4.选择Add New Ap ...
- awk程序设计语言之-awk基础
awk程序设计语言之-awk基础 http://man.linuxde.net/ 常用工具命令之awk命令 awk是一种编程语言,用于在Linux/Unix下对文本和数据处理.数据可以来自标准输入(s ...
- XP Mode 虛擬機器 for Windows 7
免驗證官方直接下載 官網 Download Windows Virtual PC XP Mode for Windows 7 性質 Windows 7 免費 / en 多國 繁體中文(Traditio ...