ACdream原创群赛(18)のAK's dream题解
只做了4题水题ADGI
A题需要注意的就是“[...]”的输出了,何时输出,何时不输出。
#include <stdio.h>
int main()
{
int n, cur, d;
int cnt = ;
while(scanf("%d%d%d",&n,&cur,&d)!=EOF)
{
printf("Case #%d: ",cnt++);
if(cur==)
printf("[<<]");
else
printf("(<<)");
int start = cur - d;
int end = cur + d;
if(start > && start!= && cur!=)//说明前面有隐藏页,需要输出[...]
printf("[...]");
for(int i=start; i<=end && i<=n; ++i)
{
if(i <= )
continue;
else
{
if(i == cur)
printf("[%d]",i);
else
printf("(%d)",i);
}
}
if(end<n && cur!=n)//说明后面有隐藏页,需要输出[...]
printf("[...]");
if(cur==n)
printf("[>>]");
else
printf("(>>)");
printf("\n"); }
}
D题应该是数学题吧(分步计数原理),将数组weight 和数组pow排序
然后分别判断每个数有多少种选择,然后一一相乘取模
对于第一个hero,如果有a1把剑的weight小于等于power,对于第二个hero,有a2把剑的weight小于等于power,一次类推
那么第一个英雄有a1种选择,第二个英雄有a2-1种选择,第三个英雄有a3-2种选择,一次类推。
至于判断有多少把剑的weight小于每个英雄的power,普通查找会超时,要用二分查找。
二分查找的特性是,对于key,如果数组中有元素与之相等,那么就返回该元素的下标,不然就返回就返回第一个比key大的元素的下标(如果有的话)
如果没有,就返回数组最后一个元素的下标。 所以我们可以用二分查找找出比power[i]小的weight有多少个
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N = + ;
const int MOD = ;
int w[N];
int p[N];
void input(int &x)
{
char ch = getchar();
while(ch<'' || ch >'')
ch = getchar();
x = ;
while(ch>='' && ch<='')
{
x = x * + ch - '';
ch = getchar();
}
}
int main()
{
int t;
int n;
int i,j,k,z;
int tCase = ;
input(t);
while(t--)
{
printf("Case #%d: ",tCase++);
input(n);
for(i=; i<=n; ++i)
input(w[i]);
for(i=; i<=n; ++i)
input(p[i]);
sort(w+, w+n+);
sort(p+, p+n+);
LL ans = ;
int cnt;
for(i=; i<=n; ++i)
{
cnt = ;
int low = ; int high = n;
int mid;
while(low <= high)
{
mid = (low + high)/;
if(p[i] == w[mid])
break;
else if(p[i] >= w[mid])
low = mid + ;
else
high = mid - ;
}
if(p[i] < w[mid])
mid--;
ans = (ans*(mid-i+))%MOD;
}
printf("%lld\n",ans);
}
}
G题要没什么,先用字符串读入,判断有没有可能爆,如果有可能,继续进一步的字符串判断,如果没可能,就用sscanf读入,然后判断范围
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
typedef long long LL;
string Max = "";//
int main()
{
int i;
string str;
LL num;
while(cin>>str)
{
if(str[] != '-')
{
if(str.size() < )
{
sscanf(str.c_str(),"%lld",&num);
if(num <= )
puts("short");
else if(num <= )
puts("int");
else
puts("long long");
}
else if(str.size()==)
{
if(str > Max)
puts("It is too big!");
else
puts("long long");
}
else
puts("It is too big!");
}
else
{
if(str.size() < )
{
sscanf(str.c_str(),"lld",&num);
if(num >= -)
puts("short");
else if(num >= )
puts("int");
else
puts("long long"); }
else if(str.size() == )
{
str.erase(str.begin());
if(str > Max)
puts("It is too big!");
else
puts("long long");
}
else
puts("It is too big!"); }
}
}
I题要注意的就是最大公约数可能是负数的情况,导致负号出现在分母。应该处理一下再输出。
#include <stdio.h>
const int N = + ;
int gcd(int n, int m)
{
if(m == )
return n;
return gcd(m,n%m);
}
int main()
{
int n, i;
int coe,exp;
while(scanf("%d",&n)!=EOF)
{
for(i=; i<n; ++i)
{
scanf("%d%d",&coe,&exp);
if( coe % (exp+)==)
printf("%d %d ",coe / (exp+),exp+);
else
{
int g = gcd(coe, exp+);
if(g>)
printf("%d/%d %d ",coe/g,(exp+)/g, exp+);
else
printf("%d/%d %d ",-coe/g,-(exp+)/g, exp+); }
}
scanf("%d%d",&coe,&exp);
if( coe % (exp+)==)
printf("%d %d\n",coe / (exp+),exp+);
else
{
int g = gcd(coe, exp+);
if(g>)
printf("%d/%d %d\n",coe/g,(exp+)/g, exp+);
else
printf("%d/%d %d\n",-coe/g,-(exp+)/g, exp+);
}
}
}
J题如果正向模拟,i要不断回溯,导致复杂度时间复杂是O(n*m).但是如果是逆向模拟,i不用回溯,时间复杂度是O(n+m).
#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N = + ;
struct node
{
int val;
int index;
bool operator<(const node &rhs)const
{
return val > rhs.val;
}
}a[N];
int hash[N];
int ans[N];
int op[N];
int main()
{
int t,n,m,tCase = ,i,j;
scanf("%d",&t);
while(t--)
{
memset(hash,,sizeof(hash));
scanf("%d%d",&n,&m);
for(i=; i<n; ++i)
{
scanf("%d",&a[i].val);
a[i].index = i;
}
sort(a,a+n);
for(i=; i<m; ++i)
scanf("%d",&op[i]);
int cnt = ;
printf("Case #%d: ",tCase++);
for(i=,j=m-;j>=;--j)
{
for(; i<n; ++i)
{
if(a[i].val <= op[j])
break;
int index = a[i].index;
hash[index] = true;
if(!hash[index-] && !hash[index+])//如果下标的左右都没有被标记过,则该下标自成一块
cnt++;
else if(hash[index-] && hash[index+])//因为该下标的加入,导致该下标的左右连在一起,2变1
cnt--;
}
ans[j] = cnt;
}
for(i=; i<m-; ++i)
printf("%d ",ans[i]);
printf("%d\n",ans[m-]); }
}
ACdream原创群赛(18)のAK's dream题解的更多相关文章
- ACdream原创群赛__15
这场感觉题目确实还算可以,不过,说好的每题10s效果上却不理想.这个时限还算比较紧.因为时间不是按绝对的多出几秒来计算,而是几倍来计算的. 比赛做的不好,后面又去做了一下. A:典型的数位DP,一直坑 ...
- ACdream原创群赛(13)のwuyiqi退役专场 C True love
True love Time Limit: 4000/2000 MS (Java/Others) Memory Limit:128000/64000 KB (Java/Others) Prob ...
- dp --- acdream原创群赛(16) --- B - Apple
<传送门> B - Apple Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Other ...
- ACdream群赛1112(Alice and Bob)
题意:http://acdream.info/problem?pid=1112 Problem Description Here is Alice and Bob again ! Alice and ...
- 使用kubeadm部署k8s集群[v1.18.0]
使用kubeadm部署k8s集群 环境 IP地址 主机名 节点 10.0.0.63 k8s-master1 master1 10.0.0.63 k8s-master2 master2 10.0.0.6 ...
- nginx集群:nginx配置负载均衡集群(nginx1.18.0)
一,nginx的负载均衡集群的特点: 1,nginx集群和lvs的不同? lvs集群:工作在第4层(传输层) nginx集群:工作在第7层(应用层) lvs集群:性能更强 nginx集群:功能更强:可 ...
- Acdream手速赛7
蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...
- ACDream手速赛2
地址:http://acdream.info/onecontest/1014 都是来自Codeforce上简单题. A. Boy or Girl 简单字符串处理 B. Walking in ...
- 群赛 ZOJ3741(dp) ZOJ3911(线段树)
zoj3741 简单dp.wa了两个小时,中间改了好多细节.后来还是不对,参考了别人的代码,发现一个致命问题,初始化的时候,不是每种状态都能直接达到的.初始化成-1. (题目有个小坑,0<=L& ...
随机推荐
- Oracle实用-01:绑定变量
数据库虽然在学校系统学习过,但是在工作中真正使用起来收获又是不一样的,今天起打算将项目中使用到的技术再分享出来,不以书本的顺序,只从碰到的问题为顺序. 虽然不是纯粹的数据库工程师,但是每个程序员总免不 ...
- python与其它语言进行比較
近期python语言貌似比較火, 今天闲来无事,简单的看了下,算是个入门吧.一门语言之所以值得这么多人去学,必然有它的独到之处,以下我们就用python和其它语言做个比較. Pythond VS C# ...
- 积累的VC编程小技巧之视图
1.如何得到视图指针 [问题提出] 现在你有一个多线程的Demo,你想在多线程里处理视图指针里的函数,我们给这个函数起个名字:Put();该如何实现呢? //有两种方法可以实现你的要求: ...
- Photon的使用
这几个月给公司一个正在做的半吊子游戏加pvp功能,一个人居然要2个多月弄个 PVP 类似 Dota 对战的游戏.我手里有套现成搭建服务端架构都没敢用起来,这服务器还是太初步了,只是验证了 Boost ...
- tmd123.com
赞!完胜百度的搜索!比baidu.com好多了! 搜索用!非常像!比baidu.com好多了! mark一下 发现有人录制了101集swift视频教程好像持续更新中......
- java Date 和 javascript Date
近期写一个页面.上面要展示下日期. 在Java中生成了Date.然后将这个Date通过velocity送入vm模板其中 代码例如以下: var dates = new Date("$!{pp ...
- uva 10581 - Partitioning for fun and profit(记忆化搜索+数论)
题目链接:uva 10581 - Partitioning for fun and profit 题目大意:给定m,n,k,将m分解成n份,然后依照每份的个数排定字典序,而且划分时要求ai−1≤ai, ...
- java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.<init>(L
关于错误: java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.&l ...
- POJ2421 & HDU1102 Constructing Roads(最小生成树)
嘎唔!~又一次POJ过了HDU错了...不禁让我想起前两天的的Is it a tree? orz..这次竟然错在HDU一定要是多组数据输入输出!(无力吐槽TT)..题目很简单,炒鸡水! 题意: 告 ...
- 用HTTP方式调用gearman任务处理
本来以为是个挺美好的东西,结果... 这样的方式非常不安全,尤其是假设暴露在公网地址,非常easy被攻击,并且gearman的http服务远没有专业的webserver健壮. 攻击方式非常easy:t ...