第一题:第几天
利用Excel表格,看行数;
利用计算器,但要加一天
答案:125
第二题:明码
这个题就是转化成二进制就可以了。
有个函数叫做bitset,可以直接转化,因为这里面的负数要用补码的形式存储,直接写的话可能很麻烦。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
using namespace std;
int main()
{
int n,m;
while(cin>>n>>m)
{
string str1,str2;
bitset<8>k(n);
str1 = k.to_string();
bitset<8>t(m);
str2 = t.to_string();
for(int i = 0; i < str1.length(); i ++)
{
if(str1[i]=='0')
printf(" ");
else
printf("*");
}
printf(" ");
for(int i = 0; i < str2.length(); i ++)
{
if(str2[i]=='0')
printf(" ");
else
printf("*");
}
printf("\n");
}
}
bitset<8>就是显示八位二进制,对于这些数字enough了。
9的9次方,利用科学计算器算一下就好惹~
这个题,eclipse,启动!
import java.math.BigDecimal;
import java.util.Scanner;
public class Blue
{
public static void main(String args[])
{
BigDecimal a,b;
Scanner scan = new Scanner(System.in);
int counts = 0;
a = scan.nextBigDecimal();
b = scan.nextBigDecimal();
while(true)
{
b = scan.nextBigDecimal();
a = a.multiply(b);
counts++;
if(counts>=98)
break;
}
System.out.println(a);
}
}
为了担心比赛的时候忘了怎么写,所以我们再来复习一遍怎么加上自动显示的下标。
打开eclipse以后点开windows->java->editor->(第一个),点不要删,大小写都打一遍。
运行出结果以后把0复制到c++里
int main()
{
string s = "0000000000000000000000000000000";
int len = s.length();
printf("%d",len);
}
算一下不容易出错。
这个题是个dp,答案:19
第五题:快速排序
答案:a,i+1,r,k-(i-l+1)
虽然填写别的答案也能过样例,但是这道题的要求是时间复杂度为O(n)。
第六题:递增三元组
这个题就是将b排序,然后看看a里面有几个比他小的,c里面有几个比他大的,tempa*tempb,然后把这些都加起来。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<cstdio>
using namespace std;
#define maxn 1000005
int a[maxn],b[maxn],c[maxn];
int main()
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; i ++)
scanf("%d",&a[i]);
for(int i = 0 ;i < n; i ++)
scanf("%d",&b[i]);
for(int i = 0; i < n; i ++)
scanf("%d",&c[i]);
sort(a,a+n);
sort(b,b+n);
sort(c,c+n);
int tempa = 0;
int tempb = 0;
int j = 0;
int sum = 0;
for(int i = 0; i < n; i ++)
{
while(a[j]<b[i])
{
tempa++;
j++;
if(j>=n)
break;
}
j = 0;
while(b[i]>c[j])
{
j++;tempb++;
if(j>=n)
break;
}
tempb = n-tempb;
j = 0;
sum += tempa*tempb;
tempa = 0,tempb = 0;
}
printf("%d",sum);
}
标题:螺旋折线
如图p1.png所示的螺旋折线经过平面上所有整点恰好一次。
对于整点(X, Y),我们定义它到原点的距离dis(X, Y)是从原点到(X, Y)的螺旋折线段的长度。
例如dis(0, 1)=3, dis(-2, -1)=9
给出整点坐标(X, Y),你能计算出dis(X, Y)吗?
【输入格式】
X和Y
对于40%的数据,-1000 <= X, Y <= 1000
对于70%的数据,-100000 <= X, Y <= 100000
对于100%的数据, -1000000000 <= X, Y <= 1000000000
【输出格式】
输出dis(X, Y)
【样例输入】
0 1
【样例输出】
3
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int x , y;
long long int res;
cin>>x>>y;
if(y > 0)
{
if(abs(x)<=y)
res = 3*y+(y*y-y)/2*8+x;
else
{
if(x > 0)
res=3*x+(x*x-x)/2*8+2*x-y;
else
res=3*-x+(x*x+x)/2*8+2*x+y;
}
}
else
{
if(y-1 <= x &&x <= -y)
res=7*-y+(y*y+y)/2*8-x;
else
{
if(x > 0)
res=7*x+(x*x-x)/2*8-2*x-y;
else
res=-7*x-7+(x*x+3*x+2)/2*8-2*x+y-1;
}
}
cout<<res;
return 0;
}
标题:日志统计
小明维护着一个程序员论坛。现在他收集了一份"点赞"日志,日志共有N行。其中每一行的格式是:
ts id
表示在ts时刻编号id的帖子收到一个"赞"。
现在小明想统计有哪些帖子曾经是"热帖"。如果一个帖子曾在任意一个长度为D的时间段内收到不少于K个赞,小明就认为这个帖子曾是"热帖"。
具体来说,如果存在某个时刻T满足该帖在[T, T+D)这段时间内(注意是左闭右开区间)收到不少于K个赞,该帖就曾是"热帖"。
给定日志,请你帮助小明统计出所有曾是"热帖"的帖子编号。
【输入格式】
第一行包含三个整数N、D和K。
以下N行每行一条日志,包含两个整数ts和id。
对于50%的数据,1 <= K <= N <= 1000
对于100%的数据,1 <= K <= N <= 100000 0 <= ts <= 100000 0 <= id <= 100000
【输出格式】
按从小到大的顺序输出热帖id。每个id一行。
【输入样例】
7 10 2
0 1
0 10
10 10
10 1
9 1
100 3
100 3
【输出样例】
1
3
看答案都是用尺取做的,但是我用vector试了一下,应该不超时,没法测评。
哎。
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
#define inf 0x3f3f3f
#define maxn 1000005
int n,d,k;
vector<vector<int> >q(maxn);
int ans[maxn];
int main()
{
scanf("%d %d %d",&n,&d,&k);
int maxx = 0,minn = inf;
for(int i = 0; i < n; i ++)
{
int t,id;
scanf("%d %d",&t,&id);
minn = min(minn,id);
maxx = max(maxx,id);
q[id].push_back(t);
}
memset(ans,0,sizeof(ans));
for(int i = minn; i <= maxx; i ++)
{
if(q[i].size()>=k)
{
sort(q[i].begin(),q[i].end());
int temp = 0;
for(int j = 0; j < q[i].size(); j ++)
{
if(q[i][temp]+d>q[i][j])
{
ans[i]++;
// printf("%d %d\n",q[i][temp]+k,q[i][j]);
if(ans[i]>=k)
break;
}
else
{
ans[i] = 0;
temp++;
j = temp;
}
}
}
}
for(int i = minn; i <= maxx; i ++)
if(ans[i]>=k)
printf("%d\n",i);
}
这是做的最后一套B组题了,这周六就要比赛了
希望能进国赛吧!~蓝桥杯请给予我力量~~~~