【T^T】【周赛】第一周周赛——欢迎16级的新同学
借光光,YZC的福气(今天拿到Rank1),本来还可以更好的,前面吃M去了,ABC都很晚切,而且异常兴奋,结果WA了好多发,但还是由于水题看题不清,分析不清导致的
A Home W的数学
Describe:我们都知道,Home W的数学最厉害了。有一天,他又开始开动脑筋了,他想:“为什么数字总是要从1排列到n呢?”于是,Home W开始研究自己排列数字的方法。首先,他写下了1-n中所有的奇数(按照升序排列),然后他又写下了1-n中所有的偶数(按照升序排列),那么问题来了,在这样的排列方式下第k个数是什么呢?
Solution:第一发getLL 结果int n。。。推推公式,奇数有x=(n+1)/2个,x<=k→k*2-1,k-=x,剩下是偶数k*2
原题:Codeforces Round #188 (Div. 2)A
Code:
// <A.cpp> - Sun Oct 9 19:01:04 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int main()
{
freopen("A.in","r",stdin);
freopen("A.out","w",stdout);
LL n=gi(),k=gi();
if(k<=(n+1)/2){
cout<<2*k-1;return 0;
}
k-=(n+1)/2;cout<<k*2;
return 0;
}
B QAQ和香蕉
Describe:QAQ是个吃货,这一次他来到了一个商店,想买w根香蕉,但是这个商店实在是黑,他需要支付k元买第一根香蕉,2k元买第二根香蕉....(也就是说,当他买第k根香蕉时,他需要支付i*k元)。可是QAQ钱包里只有n元,你能帮助他计算一下,他要借多少钱才能买下w根香蕉吗?
Solution:支出=1×k+2×k+...+w×k=(1+w)×w/2×k,与n特判一下即可
原题:Codeforces Round #304 (Div. 2)A
Code:
// <B.cpp> - Sun Oct 9 19:01:04 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#pragma GCC push_options
#pragma GCC optimize ("O2")
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=100010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int main()
{
freopen("B.in","r",stdin);
freopen("B.out","w",stdout);
LL k=gi(),n=gi(),w=gi();
if((1+w)*w/2*k<=n){cout<<0;return 0;}
cout<<(1+w)*w/2*k-n;
return 0;
}
C QAQ的数学题
Describe:Home W说他数学很好,QAQ表示不服气,于是QAQ出了一道数学题给Home W做。题目很简短:给定n个数字,每个数字最多选择一次(也可以不选,但是所有的数字中至少选择一个数字),问这n个数字不能相加得到的最小的正整数,并输出。
Notice:被坑了四发,
- 输入到文件结束( 即输入格式为 while(scanf(...)!=EOF)){ ... } )多组数据
- while中加了return 0还是多组数据的问题
- 发现特判的地方没有输回车
- 最后发现a[p]可以为零
- 本来还有第五发的,要交是测了一组数据,发现for时先要i++
Solution:Sort+贪心,当前的数>之前的和即可输出之前的和+1
证明:
从小往大加,之前可以凑出[1,r]当前加入这个数k凑出的数为一个区间[k,k+r],k>r+1,那么之后的数也会>r+1,所以r+1将凑不出.
Code:
// <C.cpp> - Sun Oct 9 19:01:04 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=1010;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int a[MAXN];int n;
int main()
{
freopen("C.in","r",stdin);
freopen("C.out","w",stdout);
while(~scanf("%d",&n)){
for(int i=1;i<=n;i++)a[i]=gi();
sort(a+1,a+1+n);int i=1;
while(!a[i])i++;
if(a[i]!=1){cout<<1<<endl;continue;}
LL m=1;bool flag=true;
for(i++;i<=n;i++){
if(a[i]>m+1){
cout<<m+1<<endl;flag=0;break;
}
m+=a[i];
}
if(flag)cout<<m+1<<endl;
}
return 0;
}
D running jump的树
Describe:
Solution:Dp,实际要求整数拆分并且有一个数要>=d的方案
f[i][0]表示拆i没有>=d的方案,f[i][1]表示有,转移见程序,cout<<f[n][1]
原题:Codeforces Round #247 (Div. 2)C
Code:
// <D.cpp> - Sun Oct 9 19:01:04 2016
// This file is made by YJinpeng,created by XuYike's black technology automatically.
// Copyright (C) 2016 ChangJun High School, Inc.
// I don't know what this program is. #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define MOD 1000000007
#define INF 1e9
#define IN inline
#define RG register
using namespace std;
typedef long long LL;
typedef long double LB;
const int MAXN=110;
const int MAXM=100010;
inline int max(int &x,int &y) {return x>y?x:y;}
inline int min(int &x,int &y) {return x<y?x:y;}
inline LL gi() {
register LL w=0,q=0;register char ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
if(ch=='-')q=1,ch=getchar();
while(ch>='0'&&ch<='9')w=w*10+ch-'0',ch=getchar();
return q?-w:w;
}
int f[MAXN][2];
int main()
{
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);
int n=gi(),k=gi(),d=gi();
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=k;j++){
if(i-j<0)continue;
if(j<d){
(f[i][0]+=f[i-j][0])%=MOD;
(f[i][1]+=f[i-j][1])%=MOD;
}else (f[i][1]+=(f[i-j][0]+f[i-j][1])%MOD)%=MOD;
}
printf("%d",f[n][1]);
return 0;
}
E Value Dragon出难题了
Describe:
有一天,Value Dragon觉得好无聊啊,所以决定出一道题目给自己做,于是他写下了一个含有n个元素的整型数组a,这n个元素分别是a1,a2,...,an。
然后呢,他就想啊,如果能找到一个连续的区间[l,r](1 ≤ l ≤ r ≤ n),使得该区间中所有的数的异或值大于等于k,那他就觉得这段区间是一个完美的区间。
那么问题来了,这样的区间总共有多少个呢?于是Value Dragon陷入了无尽的思考中......
QAQ:原题hhh~
最新文章
- 清空Github上某个文件的历史版本
- AJAX表单提交以及数据接收
- Android开发之画图的实现
- 深入理解使用ListView时ArrayAdapter、SimpleAdapter、BaseAdapter的原理
- IIS安装和使用(Windows Server 2003)
- Maven构建简单的多模块项目
- HDU 1176 免费馅饼(记忆化搜索)
- php 在函数内引用全局变量 讲解引用
- 20160729noip模拟赛zld
- HDU-4716 A Computer Graphics Problem 水题
- 检查ftp备份数据完整性及短信告警的shell脚本
- javascript基础学习(九)
- 编程算法 - 数字数组中只出现一次 代码(C)
- [Scikit-learn] 1.2 Dimensionality reduction - Linear and Quadratic Discriminant Analysis
- tomcat8权限分离
- ES6的Symbol
- javascript对象序列化(对象与JSON字符串的互换)
- 洛谷P3224 [HNOI2012]永无乡(线段树合并+并查集)
- 本地生成Rails API文档
- rest 参数和扩展运算符
热门文章
- Mybatis的一级二级缓存
- socketserver模块使用方法
- 全国高校json数据包(复python解析代码)
- Django所包含属性
- uva 12096 The SetStack Computer(STL set的各种库函数 交集 并集 插入迭代器)
- 九度oj 题目1062:分段函数
- tarjan 割点 割边
- Gym 100801 J. Journey to the “The World’s Start” DP+单调队列优化+二分
- POJ 2686_Traveling by Stagecoach【状态压缩DP】
- JFinal Weixin 微信极速 SDK