Solved A HDU 6298 Maximum Multiple
Solved B HDU 6299 Balanced Sequence
Solved C HDU 6300 Triangle Partition
Solved D HDU 6301 Distinct Values
  E HDU 6302 Maximum Weighted Matching
  F HDU 6303 Period Sequence
Solved G HDU 6304 Chiaki Sequence Revisited
Solved H HDU 6305 RMQ Similar Sequence
  I HDU 6306 Lyndon Substring
  J HDU 6307 Turn Off The Light
Solved K HDU 6308 Time Zone

A  找规律

发现只有3和4的倍数有存在答案

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops") using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
ll casn,n,m,k;
#define tpyeinput ll
inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
read(casn);
while(casn--){
read(n);
if(n>=3&&n%3==0) printf("%lld\n",((n/3ll)*(n/3ll)*(n/3ll)));
else if(n>=4&&n%4==0) printf("%lld\n",n*n*n/32ll);
else puts("-1");
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

B 贪心

去掉已经配对的,对于剩下 的,左边括号>右括号的放在左边,如果同样是左括号>右括号,不需要管哪个左括号多,只需要管哪个右括号少,右括号少的放在左边

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
#define tpyeinput int
inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
string str[maxn];
struct node {
int a,b;
}s[maxn];
int cmp(node &a,node &b){
int x=min(a.a,b.b),y=min(a.b,b.a);
return x>y||x==y&&a.a>b.a;
}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
IO;
cin>>casn;
while(casn--){
cin>>n;
rep(i,1,n){
cin>>str[i];
}
int ans=0;
rep(i,1,n){
int a=0,b=0;
rep(j,0,str[i].size()-1){
if(str[i][j]=='(') a++;
else if(str[i][j]==')'){
if(a>0) a--,ans+=2;
else b++;
}
s[i]=(node){a,b};
}
}
sort(s+1,s+1+n,cmp);
int a=0,b=0;
rep(i,1,n){
if(a>=s[i].b){
ans+=s[i].b*2;
a-=s[i].b;
}else {
ans+=a*2;
a=0;
}
a+=s[i].a;
}
cout<<ans<<endl;
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

C 画图,找规律

保证三点不共线,画图尝试之后发现规律,把点排序即可(这道题用输入挂反而会WA?)

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
//#define tpyeinput int
//inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
//inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
//inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
//inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
//inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
struct node {
int x,y,id;
}p[maxn];
bool cmp(node &a,node& b){
if(a.x==b.x) return a.y<b.y;
return a.x<b.x;
}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
IO;
cin>>casn;
while(casn--){
cin>>n;
rep(i,1,3*n){
int a,b;
cin>>a>>b;
p[i]=(node){a,b,i};
}
sort(p+1,p+1+3*n,cmp);
k=1;
rep(i,1,n){
rep(j,1,3){
cout<<p[k++].id<<' ';
}
cout<<endl;
}
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

D 双指针/贪心+小根堆维护mex

排序要求的区间,然后双指针遍历所有即可,用priority_queue维护当前双指针内的mex

卡时间,建议上输入挂

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
const int mod=1e9+7;
int casn,n,m,k;
#define tpyeinput int
inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
int ans[maxn];
int pos[maxn];
set<int>num;
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
read(casn);
while(casn--){
read(n,m);
rep(i,1,n) {
ans[i]=1;
pos[i]=i;
num.insert(i);
}
rep(i,1,m){
int a,b;
read(a,b);
pos[b]=min(pos[b],a);
}
for(int i=n-1;i;i--){
pos[i]=min(pos[i],pos[i+1]);
}
int last=1;
rep(i,1,n){
while(last<pos[i]){
num.insert(ans[last]);
last++;
}
ans[i]=*num.begin();
num.erase(ans[i]);
}
rep(i,1,n){
printf("%d%c",ans[i]," \n"[i==n]);
}
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

G 找规律+打表倍增

找规律发现,数列中$X$的出现次数是$lowbit(X)$,于是对于出现次数相同的值(也就是$lowbit(x)$相同)的数,构成了等差数列..

原数列就是很多个等差数列构成的了,然后先预处理一下值,每次有多少个不同的等差数列,求和即可...

具体看代码

#include <bits/stdc++.h>
#define ll long long
#define show(x) cout<<#x<<"="<<x<<endl
#define show2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<endl
#define show3(x,y,z) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define show4(w,x,y,z) cout<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define show5(v,w,x,y,z) cout<<#v<<" "<<v<<" "<<#w<<"="<<w<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<endl
#define showa(a,b) cout<<#a<<'['<<b<<"]="<<a[b]<<endl
#define print(x) cout<<#x<<"="<<x<<' '
#define ptline() cout<<endl
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const ll mod=1e9+7;
const int INF=0x3f3f3f3f;
ll casn,n,m,k;
#define tpyeinput ll
inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
ll num[maxn],p[maxn];
ll inv=(mod+1)/2;
void init(){
num[0]=p[0]=1;
rep(i,1,63){
num[i]=num[i-1]*2ll+1ll;
p[i]=p[i-1]*2ll;
}
}
ll cal(ll pos){
ll sum=0;
for(ll i=1;i<=pos;i*=2ll){
ll num=(pos-i)/(2*i);
ll m=i+num*(2ll*i);;
num=(num+1ll)%mod;
m=(m+i)%mod;
m=m*num%mod;
m=m*inv%mod;
m=m*(__builtin_ctz(i)+1ll)%mod;
sum=(sum+m)%mod;
}
return (sum+1)%mod;
}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
read(casn);
init();
while(casn--){
read(n);
n--;
if(!n){
puts("1");
continue;
}
ll tmp=n;
ll pos=0;
for(int i=62;i>=0;i--){
if(tmp>=num[i]){
tmp-=num[i];
pos+=p[i];
}
}
ll sum=cal(pos);
if(tmp){
sum=(sum+tmp%mod*(pos+1ll)%mod)%mod;
}
printf("%lld\n",sum);
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

H 组合数学+笛卡尔树性质

笛卡尔树的2个重要性质,

1.中序遍历等于原序列,换句话说,就是把树拍扁等价于原数列

2.区间的最大元素,就是表示了这个区间的子树的根节点

放到这个题里,就是笛卡尔树的形状和题目给的一样,问你多少种...

组合数学,dfs笛卡尔树记算总种类数,过程中需要求逆元...

代码里的这个笛卡尔树和线性推逆元是学的dls..

推导参考出题大爷:

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e6+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
const ll mod=1e9+7;
#define tpyeinput int
inline char nc() {static char buf[1000000],*p1=buf,*p2=buf;return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;}
inline void read(tpyeinput &sum) {char ch=nc();sum=0;while(!(ch>='0'&&ch<='9')) ch=nc();while(ch>='0'&&ch<='9') sum=(sum<<3)+(sum<<1)+(ch-48),ch=nc();}
inline void read(tpyeinput &num1,tpyeinput &num2){read(num1);read(num2);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3){read(num1);read(num2);read(num3);}
inline void read(tpyeinput &num1,tpyeinput &num2,tpyeinput &num3,tpyeinput &num4){read(num1);read(num2);read(num3);read(num4);}
int casn,n,m,k;
struct node{int l,r;}ctree[maxn];
ll inv[maxn],ans;
int stk[maxn],vis[maxn];
pair<int,int> num[maxn];
#define nd ctree[now]
int dfs(int now){
if(now==0)return 0;
int sum=dfs(nd.l)+dfs(nd.r)+1;
ans=ans*inv[sum]%mod;
// cout<<ans<<endl;
return sum;
}
void maketree(){
int top=0;
rep(i,1,n){
int now=top;
while(now&&num[stk[now-1]]>num[i]) now--;
if(now) ctree[stk[now-1]].r=i;
if(now<top) ctree[i].l=stk[now];
stk[now++]=i;
top=now;
}
}
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
inv[1]=1;
rep(i,2,maxn-5)inv[i]=inv[mod%i]*(mod-mod/i)%mod;
read(casn);
while(casn--){
read(n);
rep(i,1,n){
int x;
read(x);
num[i]=make_pair(-x,i);
}
ans=inv[2]*(ll)n%mod;
// cout<<ans<<endl;
rep(i,1,n) ctree[i]=(node){0,0},vis[i]=0;
maketree();
rep(i,1,n) vis[ctree[i].l]=vis[ctree[i].r]=1;
int rt=0;
rep(i,1,n) if(vis[i]==0) {
rt=i;break;
}
dfs(rt);
printf("%lld\n",ans);
}
#ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

K 模拟题

难点有2个

输入,误差..

输入建议用"scanf("%d %d UTC%c%lf",&h,&m,&flag,&utc);";

    也可以"cin>>h>>m>>ch>>ch>>ch>>ch>>utc";

误差就是$1.4$会被读入为$1.39999$取整变成$1.3$之类的

utc+=0.001就行了,消除误差,而且不影响答案

#include <bits/stdc++.h>
#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(ii,a,b) for(int ii=a;ii<=b;ii++)
using namespace std;
const int maxn=1e5+10;
const int maxm=1e6+10;
const int INF=0x3f3f3f3f;
int casn,n,m,k;
int main(){
//#define test
#ifdef test
freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#endif
scanf("%d",&casn);
int h,m,flag,ch,x;
double y;
while(casn--){
y=0;
double tt;
scanf("%d %d UTC%c%lf",&h,&m,&flag,&tt);
tt+=0.0001;
x=(int)tt;
y=tt-x;
y*=10;
if(flag=='-') {
x=-(x+8);
y=-y;}
else x-=8;
int t1=x;
int t2=y*6;
h+=t1;
m+=t2;
if(m>=60){
m-=60;
h++;
}
if(h>=24) h-=24;
if(m<0){
m+=60;
h--;
}if(h<0){
h+=24;
}
printf("%02d:%02d\n",h,m);
} #ifdef test
fclose(stdin);fclose(stdout);system("out.txt");
#endif
return 0;
}

  

2018 Multi-University Training Contest - Team 1 题解的更多相关文章

  1. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  2. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  3. 2017 Multi-University Training Contest - Team 3 hdu6060 RXD and dividing

    地址:http://acm.split.hdu.edu.cn/showproblem.php?pid=6060 题目: RXD and dividing Time Limit: 6000/3000 M ...

  4. HDU 6038.Function-数学+思维 (2017 Multi-University Training Contest - Team 1 1006)

    学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o 我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)... 数学+思维题,代码懂了,也能写出来,但是还是 ...

  5. HDU 6166.Senior Pan()-最短路(Dijkstra添加超源点、超汇点)+二进制划分集合 (2017 Multi-University Training Contest - Team 9 1006)

    学长好久之前讲的,本来好久好久之前就要写题解的,一直都没写,懒死_(:з」∠)_ Senior Pan Time Limit: 12000/6000 MS (Java/Others)    Memor ...

  6. 2017 Multi-University Training Contest - Team 2&&hdu 6047 Maximum Sequence

    Maximum Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  8. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  9. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

随机推荐

  1. python 面向对象(经典作业讲解)

    #############################总结######################## # lst =['python%s期' %i for i in range(510)]# ...

  2. css3 transition和animation的区别与联系

    1. transition 一定时间之内,一组css属性变换到另一组属性的动画展示过程. 属性: transition-property:动画展示哪些属性,可以使用all关键字: transition ...

  3. 前端常用UI框架

    移动端UI框架 Mint UI(饿了么团队) 中文官网:http://mint-ui.github.io/#!/en 饿了么前端团队推出的基于Vue.js的移动端组件库 GitHub地址:https: ...

  4. [Android] Android : lambda expressions are not supported at this language level(需设置project language level)

    最近在Github上下载一个别人的开源项目 ,里面用到了Javajdk1.8的新特性:Lambda 表达式.而我用的Android studio发现不能用这个Lambda 表达式. 本地环境: And ...

  5. SpringBoot系列: Json的序列化和反序列化

    ============================= 控制 json 序列化/反序列化=============================1. @JsonIgnoreProperties的 ...

  6. 开源框架.netCore DncZeus学习(三)增加一个菜单

    框架运行起来了,先尝试增加一个菜单. 本节增加一个菜单名字:公司管理,需要注意一点,所有的name都要保持一致,注意圈中部分.为了防止手敲代码出错,建议复制已有的代代码进行修改(比如这里用的Role页 ...

  7. php下curl ssl常用问题

    1. 查看curl版本 在phpinfo中,可以查看 curl cURL support enabled cURL Information 7.35.0 Age 3 Features AsynchDN ...

  8. 使用aspectJ实现Spring AOP的两种方式

    方式一:基于aspectJ的XML配置 方式二:基于aspectJ的注解方式 基于aspectJ的XML配置 1)       引入相关jar包 2)       创建Spring核心配置文件,必须导 ...

  9. luogu 1966 火柴排队 离散化+逆序对

    题意:找到最小改变对数使a数组的第i大和b数组的第i大相等 则先将a,b,数组编号再排序,则数组显示的就是排名第i的数的编号 再关键一步:c[a[i].id]=b[i].id 实质上就是新建一个数组, ...

  10. VGG-16详解

    VGG16输入224*224*3的图片,经过的卷积核大小为3x3x3,stride=1,padding=1,pooling为采用2x2的max pooling方式: 1.输入224x224x3的图片, ...