上一场CF打到心态爆炸,这几天也没啥想干的

A Math Problem

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
You are given a positive integer n, please count how many positive integers k satisfy kk≤n.
 
Input
There are no more than 50 test cases.

Each case only contains a positivse integer n in a line.

1≤n≤1018

 
Output
For each test case, output an integer indicates the number of positive integers k satisfy kk≤n in a line.
 
Sample Input
1
4
 
Sample Output
1
2
第一题就是直接枚举啊,肯定很快就到上限了,测一下最大的最好了
是输出15,我还傻傻输出错了,本来只考虑了位数

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=;
int main()
{
ll n;
while(~scanf("%lld",&n))
{
if(n>=N)
printf("15\n");
else
{
for(int k=; k<; k++)
{
ll s=;
for(int i=; i<k; i++)
s*=k;
if(s>n)
{
printf("%d\n",k-);
break;
}
}
}
}
return ;
}

Covering

Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Bob's school has a big playground, boys and girls always play games here after school.

To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets.

Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more.

He has infinite carpets with sizes of 1×2 and 2×1, and the size of the playground is 4×n.

Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping?

 
Input
There are no more than 5000 test cases.

Each test case only contains one positive integer n in a line.

1≤n≤1018

 
Output
For each test cases, output the answer mod 1000000007 in a line.
 
Sample Input
1
2
 
Sample Output
1
5
经典骨牌覆盖,可以找到递推式
1 5 11 36 95 281 2245 6336 18061 51205 145601
a[n]=a[n-1]+5*a[n-2]+a[n-3]-a[n-4]; 
 
#include <stdio.h>
#include <string.h>
const int MD=1e9+;
typedef long long LL;
struct matrix
{
LL mat[][];
};
matrix matmul(matrix a,matrix b,int n)
{
int i,j,k;
matrix c;
memset(c.mat,,sizeof(c.mat));
for(i=; i<n; i++)
{
for(j=; j<n; j++)
{
for(k=; k<n; k++)
{
c.mat[i][j]=(c.mat[i][j]+a.mat[i][k]*b.mat[k][j])%MD;
}
}
}
return c;
}
matrix matpow(matrix a,LL k,int n)
{
matrix b;
int i;
memset(b.mat,,sizeof(b.mat));
for(i=; i<n; i++) b.mat[i][i]=;
while(k)
{
if(k&) b=matmul(a,b,n);
a=matmul(a,a,n);
k>>=;
}
return b;
}
int main()
{
LL k;
matrix a,b;
memset(a.mat,,sizeof(a.mat));
memset(b.mat,,sizeof(b.mat));
a.mat[][]=,a.mat[][]=,a.mat[][]=;
b.mat[][]=,b.mat[][]=,b.mat[][]=,b.mat[][]=-;
b.mat[][]=,b.mat[][]=,b.mat[][]=;
while(~scanf("%lld",&k))
{
printf("%lld\n",(matmul(matpow(b,k,),a,).mat[][]+MD)%MD);
}
return ;
}

CS Course

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 0    Accepted Submission(s): 0

Problem Description
Little A has come to college and majored in Computer and Science.

Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework.

Here is the problem:

You are giving n non-negative integers a1,a2,⋯,an, and some queries.

A query only contains a positive integer p, which means you 
are asked to answer the result of bit-operations (and, or, xor) of all the integers except ap.

 
Input
There are no more than 15 test cases.

Each test case begins with two positive integers n and p
in a line, indicate the number of positive integers and the number of queries.

2≤n,q≤105

Then n non-negative integers a1,a2,⋯,an follows in a line, 0≤ai≤109 for each i in range[1,n].

After that there are q positive integers p1,p2,⋯,pqin q lines, 1≤pi≤n for each i in range[1,q].

 
Output
For each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except ap in a line.
 
Sample Input
3 3
1 1 1
1
2
3
 
Sample Output
1 1 0
1 1 0
1 1 0

异或最简单,再异或一次就好了

所以按位存储了

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+;
int a[N],b[N];
int main()
{
int n,m;
while(~scanf("%d%d",&n,&m))
{
memset(b,,sizeof(b));
int Xor=,And=0xffffffff,Or=;
for(int i=; i<=n; i++)
{
int x;
scanf("%d",&x);
a[i]=x;
And&=x;
Or|=x;
Xor^=x;
for(int j=; x; j++,x>>=)
b[j]+=x%;
}
while(m--)
{
int q;
scanf("%d",&q);
q=a[q];
int A=And,O=Or,X=Xor;
X=X^q;
for(int j=; j<=; j++,q>>=)
{
if(b[j]==n-&&q%==)A+=(<<j);
if(b[j]==&&q%)O-=(<<j);
}
printf("%d %d %d\n",A,O,X);
}
}
return

Duizi and Shunzi

Nike likes playing cards and makes a problem of it.

Now give you n integers, ai(1≤i≤n)ai(1≤i≤n)

We define two identical numbers (eg: 2,22,2) a Duizi, 
and three consecutive positive integers (eg: 2,3,42,3,4) a Shunzi.

Now you want to use these integers to form Shunzi and Duizi as many as possible.

Let s be the total number of the Shunzi and the Duizi you formed.

Try to calculate max(s)max(s).

Each number can be used only once. 

InputThe input contains several test cases.

For each test case, the first line contains one integer n(1≤n≤1061≤n≤106). 
Then the next line contains n space-separated integers aiai (1≤ai≤n1≤ai≤n) 
OutputFor each test case, output the answer in a line. 
Sample Input

7
1 2 3 4 5 6 7
9
1 1 1 2 2 2 3 3 3
6
2 2 3 3 3 3
6
1 2 3 3 4 5

Sample Output

2
4
3
2

Hint

Case 1(1,2,3)(4,5,6)

Case 2(1,2,3)(1,1)(2,2)(3,3)

Case 3(2,2)(3,3)(3,3)

Case 4(1,2,3)(3,4,5)

这个题看起来很简单,问你最多可形成多少个对子和顺子

可是有坑啊,可以按照对子打,也可以按照顺子打,我当然按照对子打了,但是按照对子打可能我的顺子就没了,所以我首先是要打足够多的牌

比如我往下贪心的时候,如果第二张恰好是对子,我贪心就亏了,但是我下一张正好三张我肯定就要了这个顺子

所以就是记录顺子和找对子了

#include <stdio.h>
#include <string.h>
const int N=1e5+;
int a[N];
int main()
{
int n;
while(~scanf("%d",&n))
{
memset(a,,sizeof(int)*(n+));
for(int i=; i<n; i++)
{
int x;
scanf("%d",&x);
a[x]++;
}
int ans=;
for(int i=; i<n-; i++)
{
ans+=a[i]/;
if(a[i]&&&a[i+]&&&a[i+])
{
ans++;
a[i+]--;
a[i+]--;
}
}
ans+=a[n-]/+a[n]/;
printf("%d\n",ans);
}
return ;
}

最新文章

  1. DataTime格式化大全(转载)
  2. Oracle数据库11g基于rehl6.5的配置与安装
  3. IDEA UML类图插件
  4. linux环境进程的停止
  5. 百度编辑器ueditor代码高亮效果前台不显示的解决方法
  6. 关于Linux的总结(二)
  7. 2.1CUDA-Thread
  8. iOS UICollectionView基础
  9. Android 不能勾选 Project Build Target
  10. javabean+servlet+jsp程序_个人辛苦探索
  11. MVC4中 jquery validate 不用submit方式验证表单或单个元素
  12. 手势(Gesture)的增加和识别
  13. mysql中国的内容php网页乱码问题
  14. [CLR via C#]1.2 将托管模块合并成程序集
  15. MySQL-8.0.11与Navicat Premium安装教程
  16. laravel5.3安装redis扩展包
  17. GO语言的进阶之路-面向对象编程
  18. python - classs内置方法 solt
  19. oracle中主键自增
  20. python二进制转换

热门文章

  1. 本机运行x程序出现:Can&#39;t open display 原因及其解决方法(貌似非永久)
  2. Git服务器和Git权限管理应用GITLAB安装方法
  3. 理想路径——双向BFS
  4. 120. Triangle 以及一个多维vector如何初始化
  5. 如何在Mac OS X中开启或关闭显示隐藏文件命令
  6. js中声明函数的三种方式
  7. Python基础篇 -- 运算符和编码
  8. PAT (Advanced Level) Practise - 1098. Insertion or Heap Sort (25)
  9. jquery操作滚动条滚动到指定元素位置 scrollTop
  10. 低性能3张图片轮播React组件