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& ...
随机推荐
- 【Demo 0011】多媒体播放器
本章学习要点: 1. 掌握AVAudioPlayer 基本使用; 2. 掌握AVPlayer 基本使用; 3. 掌握系统声音播放以及震动; 4. ...
- 回文(manacher)
裸manacher 我竟然写跪了………… 一个地方(偶数)没写清楚…… 我OOXOXOXOXXOXO #include<cstdio> #include<cstdlib> #i ...
- Swift - 按钮(UIButton)的用法
1,按钮的创建 (1)按钮有下面四种类型: UIButtonType.ContactAdd:前面带“+”图标按钮,默认文字颜色为蓝色,有触摸时的高亮效果 UIButtonType.DetailDisc ...
- spice for openstack
nova.conf vnc_enabled=False [Spice] agent_enabled=True enabled=True html5proxy_base_url=http://x.x.x ...
- Mybatis自己主动生成代码
在mybatis自己主动生成代码有两种方式: 方式一:是通过使用eclipse作为开发工具.採用maven来构建项目生成的.以下的演示是通过第一种方式. 今天来记录下mybatis-generator ...
- 积累的VC编程小技巧之组合框
1.如何正确的得到ComBox的指针 CComboBox *mComb = (CComboBox*)GetDlgItem(IDC_DuanCB); CComboBox *mComb = (CCombo ...
- Android照片墙完整版,的完美结合LruCache和DiskLruCache
转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/34093441 在上一篇文章其中,我们学习了DiskLruCache的概念和基本使用 ...
- gcc入门
gcc入门 1. 什么是gcc gcc的全称是GUN Compiler Collection,它是一个能够编译多种语言的编译器.最开始gcc是作为C语言的编译器(GNU C Compiler),现在除 ...
- BroadcastReceiver总结
一.工程整体图 二.activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ ...
- IDEA系统提示中文乱码问题及解决
近期要切换到IDEA开发, 在输出界面发现打印小方格, 或者乱码, 是由于字体不支持中文, 选择一个支持中文的就正常了.(由于IDEA在国内下载错误信息会用中文显示. 而之前Eclipse错误都是英文 ...