The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)
http://acm.zju.edu.cn/onlinejudge/showContestProblems.do?contestId=391
A Thanks, TuSimple!
Time Limit: 1 Second Memory Limit: 65536 KB
题意:有t组数据,n个男生,m个女生,每个人身高不同,每个人都期望和比自己高或者比自己低的人跳舞,问最多有多少对舞伴
题解:把期待比自己高的男生身高和期待比自己低的男生身高分别存在两个数组a[n],b[n]里,同理对女生也进行这样的操作c[n],d[n],分别对这四个数组进行排序,对于期望比自己的高的男生来说应该找到期望比自己低的女生,这时就可以从a[1]开始找对应的满足条件的d[i](也就是比自己高的女生),同理可以从c[1]开始找对应的满足条件的b[i],(由于排序之后的单调性,所以二者的期望单调性也完全吻合所以正确性也很显然)统计个数即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[],b[],q[],w[],e[],r[];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
}
for(int i=;i<=m;i++){
scanf("%lld",&b[i]);
}
int tot1,tot2,tot3,tot4;
tot1=tot2=tot3=tot4=;
for(int i=;i<=n;i++){
int c;
scanf("%d",&c);
if(c){
q[++tot1]=a[i];
}
else{
w[++tot2]=a[i];
}
}
for(int i=;i<=m;i++){
int c;
scanf("%d",&c);
if(c){
e[++tot3]=b[i];
}
else{
r[++tot4]=b[i];
}
}
sort(q+,q++tot1);
sort(w+,w++tot2);
sort(e+,e++tot3);
sort(r+,r++tot4);
int pos1=;
int ans=;
for(int i=;i<=tot1;i++){
while(pos1<=tot4&&r[pos1]<q[i])pos1++;
if(pos1<=tot4){
ans++;
pos1++;
}
else{
break;
}
}
pos1=;
for(int i=;i<=tot3;i++){
while(pos1<=tot2&&w[pos1]<e[i])pos1++;
if(pos1<=tot2){
ans++;
pos1++;
}
else{
break;
}
}
printf("%d\n",ans);
}
return ;
}
B Even Number Theory
Time Limit: 1 Second Memory Limit: 65536 KB
题意:给了一堆定义,就是求 e/2+e/4+e/8+e/16.....+0 的值
题解:大数除法+大数加法(模板要用对..板子不对超时一万年..当然也可以使用java,但是我不会)
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define MAXN 9999
#define MAXSIZE 1010
#define DLEN 4
class BigNum{
private:
int a[]; //可以控制大数的位数
int len;
public:
BigNum(){len=;memset(a,,sizeof(a));} //构造函数
BigNum(const int); //将一个 int 类型的变量转化成大数
BigNum(const char*); //将一个字符串类型的变量转化为大数
BigNum(const BigNum &); //拷贝构造函数
BigNum &operator=(const BigNum &); //重载赋值运算符,大数之间进行赋值运算
friend istream& operator>>(istream&,BigNum&); //重载输入运算符
friend ostream& operator<<(ostream&,BigNum&); //重载输出运算符
BigNum operator+(const BigNum &)const; //重载加法运算符,两个大数之间的相加运算
BigNum operator-(const BigNum &)const; //重载减法运算符,两个大数之间的相减运算
BigNum operator*(const BigNum &)const; //重载乘法运算符,两个大数之间的相乘运算
BigNum operator/(const int &)const; //重载除法运算符,大数对一个整数进行相除运算
BigNum operator^(const int &)const; //大数的 n 次方运算
int operator%(const int &)const; //大数对一个类型的变量进行取模运算int
bool operator>(const BigNum &T)const; //大数和另一个大数的大小比较
bool operator>(const int &t)const; //大数和一个 int 类型的变量的大小比较
void print(); //输出大数
};
BigNum::BigNum(const int b){
int c, d = b; len=;
memset(a,,sizeof(a));
while(d>MAXN){
c=d-(d/(MAXN+))*(MAXN+);
d=d/(MAXN+);
a[len++]=c;
}
a[len++]=d;
}
BigNum::BigNum(const BigNum &T):len(T.len){
int i;
memset(a,,sizeof(a));
for(i=;i<len;i++)
a[i]=T.a[i];
} BigNum & BigNum::operator=(const BigNum &n){
int i;
len=n.len;
memset(a,,sizeof(a));
for(i=;i<len;i++)
a[i]=n.a[i];
return *this;
}
istream& operator>>(istream &in,BigNum &b){
char ch[MAXSIZE*];
int i=-;
in>>ch;
int L=strlen(ch);
int count=,sum=;
for(i=L-;i>=;){
sum=;
int t=;
for(int j=;j<&&i>=;j++,i--,t*=){
sum+=(ch[i]-'')*t;
}
b.a[count]=sum;
count++;
}
b.len=count++;
return in;
}
ostream& operator<<(ostream& out,BigNum& b){
int i;
cout<<b.a[b.len-];
for(i=b.len-;i>=;i--){
printf("%04d",b.a[i]);
}
return out;
}
BigNum BigNum::operator/(const int &b)const{
BigNum ret;
int i,down=;
for(i=len-;i>=;i--){
ret.a[i]=(a[i]+down*(MAXN+))/b;
down=a[i]+down*(MAXN+)-ret.a[i]*b;
}
ret.len=len;
while(ret.a[ret.len-]== && ret.len>)
ret.len--;
return ret;
}
BigNum BigNum::operator+(const BigNum &T)const{
BigNum t(*this);
int i,big;
big=T.len>len?T.len:len;
for(i=;i<big;i++){
t.a[i]+=T.a[i];
if(t.a[i]>MAXN){
t.a[i+]++;
t.a[i]-=MAXN+;
}
}
if(t.a[big]!=)
t.len=big+;
else t.len=big;
return t;
} bool BigNum::operator>(const BigNum &T)const{
int ln;
if(len>T.len)return true;
else if(len==T.len){
ln=len-;
while(a[ln]==T.a[ln]&&ln>=)
ln--;
if(ln>= && a[ln]>T.a[ln])
return true;
else return false;
}
else return false;
}
bool BigNum::operator>(const int &t)const{
BigNum b(t);
return *this>b;
}
int main(){
int t;
cin>>t;
while(t--){
BigNum a;
cin>>a;
BigNum ans;
ans=;
while(a>){
a=a/;
ans=ans+a;
}
cout<<ans<<endl;
}
return ;
}
C Robot Cleaner I
Time Limit: 1 Second Memory Limit: 65536 K
题意:给出n*m的格子地图,0表示空地,1表示墙壁,2表示有垃圾的空地,然后给出一段包含L,R,U,D,P(清理垃圾),I的操作序列(长度恒为243),然后定义一个t(i,j)=mp[i]*3^4+mp[i-1]*3^3+mp[i+1][j]*3^2+mp[i][j-1]*3+mp[i][j+1],其中i,j表示所在位置的坐标,每次执行那段操作序列的第t(i,j)+1个字符表示的操作(不能移动到墙的位置,每个垃圾只能被清理一次),一共执行k次操作(k<=10^18),问最终能清理多少垃圾
题解:如果这道题没有清理垃圾之后mp[i][j]从2变为0的步骤,那么直接记录每个位置是否被访问到,如果被访问就退出即可,因为走过一次的路再走还是那一条路,但是这里的mp[i][j]会随着清扫工作而改变,所以需要记录每个位置被走过的次数,如果>n*m就退出,由于n*m<=2e4,所以大概4e8的复杂度..可以通过
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
int vis[][];
char ch[];
char q[][];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,m;
scanf("%d%d",&n,&m);
ll a,b,k;
scanf("%lld%lld%lld",&a,&b,&k);
scanf("%s",ch+);
for(int i=;i<=n;i++){
scanf("%s",q[i]+);
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
for(int s=;s<;s++){
vis[(i-)*m+j][s]=;
}
}
}
vis[(a-)*m+b][q[a][b]-'']=;
int ans=;
while(k){
k--;
int sum=****(q[a][b]-'');
sum++;
if(a>){
sum+=(q[a-][b]-'')***;
}
if(a<n){
sum+=(q[a+][b]-'')**;
}
if(b>){
sum+=(q[a][b-]-'')*;
}
if(b<m){
sum+=(q[a][b+]-'');
}
if(sum>)break;
if(ch[sum]=='L'){
b--;
if((q[a][b]-'')==)b++;
}
if(ch[sum]=='R'){
b++;
if((q[a][b]-'')==)b--;
}
if(ch[sum]=='U'){
a--;
if((q[a][b]-'')==)a++;
}
if(ch[sum]=='D'){
a++;
if((q[a][b]-'')==)a--;
}
if(ch[sum]=='P'){
if((q[a][b]-'')==){
q[a][b]='';
ans++;
}
}
if(vis[(a-)*m+b][(q[a][b]-'')]>n*m)break;
vis[(a-)*m+b][(q[a][b]-'')]++;
}
printf("%d\n",ans);
}
return ;
}
E Potion
Time Limit: 1 Second Memory Limit: 65536 KB
题意:给两个数组a[n],b[n],如果b[n]可以高位向低位移动物品,问能否通过若干次操作使对于 1<=i<=n 都可以a[i]<=b[i]
题解:由于可以从高位向低位移动,所以只需要倒着做,如果b[i]>a[i],就把多出的部分移动到b[i-1],如果b[i]<a[i]就证明不能通过若干次操作完成题目要求
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[],b[];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
int f=;
for(int i=;i<=n;i++)scanf("%lld",&a[i]);
for(int i=;i<=n;i++)scanf("%lld",&b[i]);
for(int i=n;i>=;i--){
if(b[i]>=a[i]){
b[i-]+=b[i]-a[i];
}
else{
f=;
break;
}
}
if(f)printf("Yes\n");
else printf("No\n");
}
return ;
}
G Postman
Time Limit: 1 Second Memory Limit: 65536 KB
题意:给一个序列,表示n个邮箱,邮局在0处,小明每次可以最多携带k封信,最终结束地点可以不在邮局,问小明走的最短的距离
题解:贪心地想把尽量远的封信放在一起送,最后由于可以不在邮局结束,所以结果要减去最远的那次距离
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[];
int main(){
int t;
scanf("%d",&t);
while(t--){
int n,k;
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%lld",&a[i]);
}
sort(a+,a++n);
int pos=upper_bound(a+,a++n,)-a;
ll sum=;
int i;
ll maxx=;
for(i=n;i>=pos;i-=k){
sum+=*a[i];
}
maxx=max(abs(a[n]),abs(a[]));
pos=min(pos,n);
while(pos>=&&a[pos]>=)pos--;
for(i=;i<=pos;i+=k){
sum+=*abs(a[i]);
}
printf("%lld\n",sum-maxx);
}
return ;
}
J Extended Twin Composite Number
Time Limit: 1 Second Memory Limit: 65536 KB Special Judge
题意:给出一个n,求 满足x+n=y并且x,y是非质数的一组解
题解:x=8*n y=9*n,x y 就一定不是质数且满足等式
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
ll a[],b[];
int main(){
int t;
scanf("%d",&t);
while(t--){
ll n;
scanf("%lld",&n);
printf("%lld %lld\n",n*,n*);
}
return ;
}
The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror)的更多相关文章
- The 19th Zhejiang University Programming Contest Sponsored by TuSimple (Mirror) B"Even Number Theory"(找规律???)
传送门 题意: 给出了三个新定义: E-prime : ∀ num ∈ E,不存在两个偶数a,b,使得 num=a*b;(简言之,num的一对因子不能全为偶数) E-prime factorizati ...
- zoj 4020 The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light(广搜)
题目链接:The 18th Zhejiang University Programming Contest Sponsored by TuSimple - G Traffic Light 题解: 题意 ...
- Mergeable Stack 直接list内置函数。(152 - The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意:模拟栈,正常pop,push,多一个merge A B 形象地说就是就是将栈B堆到栈A上. 题解:直接用list 的pop_back,push_back,splice 模拟, 坑:用splice ...
- 152 - - G Traffic Light 搜索(The 18th Zhejiang University Programming Contest Sponsored by TuSimple )
http://acm.zju.edu.cn/onlinejudge/showContestProblem.do?problemId=5738 题意 给你一个map 每个格子里有一个红绿灯,用0,1表示 ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple -C Mergeable Stack
题目链接 题意: 题意简单,就是一个简单的数据结构,对栈的模拟操作,可用链表实现,也可以用C++的模板类来实现,但是要注意不能用cin cout,卡时间!!! 代码: #include <std ...
- The 18th Zhejiang University Programming Contest Sponsored by TuSimple
Pretty Matrix Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid's birthday is coming. As hi ...
- ZOJ 4016 Mergeable Stack(from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; str ...
- ZOJ 4019 Schrödinger's Knapsack (from The 18th Zhejiang University Programming Contest Sponsored by TuSimple)
题意: 第一类物品的价值为k1,第二类物品价值为k2,背包的体积是 c ,第一类物品有n 个,每个体积为S11,S12,S13,S14.....S1n ; 第二类物品有 m 个,每个体积为 S21,S ...
- The 17th Zhejiang University Programming Contest Sponsored by TuSimple J
Knuth-Morris-Pratt Algorithm Time Limit: 1 Second Memory Limit: 65536 KB In computer science, t ...
随机推荐
- elment重置表格行高,hover效果
来源网络,做个笔记.表头行高.el-table__header tr, .el-table__header th { padding: 0; height: 50px; }表体行高 .el-table ...
- 记初学python的一些心得
人生苦短,我用python! 其实我自学python也很长一段时间了,但总是去更换学习资料,搞的现在学的不是很好,因为没更换次资料都要从头开始学起,那么分享下我的学习战况吧,不是很好,还将就的能看. ...
- ESP32搭建1.VMware Workstation 12.5下Ubuntu16.04环境搭建(简易搭建)
一.需要下载的资源: 1. 下载VMware Workstation 链接: https://pan.baidu.com/s/1nuDEc3n 密码: 89xc 2. 下载Ubuntu ...
- OTP&ETS
最近觉得实在是该梳理梳理erlang的框架内容了,所以整理了下. OTP(开放电信平台):并发系统平台, 特点:容错(erlang:get_stacktrace(),try-catch,trap_ex ...
- js中三种弹出框
javascript的三种对话框是通过调用window对象的三个方法alert(),confirm()和prompt()来获得,可以利用这些对话框来完成js的输入和输出,实现与用户能进行交互的js代码 ...
- Python基础(条件判断,循环,占位符等)
Python 自动化 系统开发用的语言和自动化脚本可以不同 学习peython可用于: 网路爬虫,数据分,web开发,人工智能,自动化运维,自动化测试,嵌入式,黑客 第三方库比较全 脚本语言:功能单一 ...
- vue-baidu-map 的简单使用
首先附上vue-baidu-map 文档地址: https://dafrok.github.io/vue-baidu-map/#/zh/index 1.安装,初步使用,文档说的都很明白,就不在过多重复 ...
- Javascript设计模式记录
prototype与面向对象取舍 使用prototype原型继承和使用面向对象,都可以实现闭包的效果.那么这两个的选择点,就是方法会不会产生多个实例. 例如,我们需要做一个闭包数组,并给他提供一个添加 ...
- Linux CentOS 7 下的C++ 学习笔记01
1.虚拟机WMware 通过镜像安装CentOS 7系统(自行百度操作 虚拟机+镜像+安装一套都有) //安装时需要配置网络 //root设置密码 即为登录系统的账号和密码 2. C++ 环境设置 ...
- JAVA作业三
(一)学习总结 1.阅读下面程序,分析是否能编译通过?如果不能,说明原因.应该如何修改?程序的运行结果是什么?为什么子类的构造方法在运行之前,必须调用父 类的构造方法?能不能反过来? class Gr ...