A1008
#include<iostream>
using namespace std;
const int maxn=111;
int a[maxn],n;
int main()
{
cin >> n;
int next,qian=0;
int time=0;
for(int i=0; i<n; i++)
{
cin >> next;
if(next>qian)
{
time+=(next-qian)*6;
}
else
{
time+=(qian-next)*4;
}
qian=next;
}
time+=n*5;
cout << time;
return 0;
}
A1011
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
double res=1;
for(int i=0; i<3; i++)
{
double w,t,l;
cin >> w >> t >> l;
double x=max(w,max(t,l));
if(x==w)
cout << "W ";
else if(x==t)
cout << "T ";
else
cout << "L ";
res*=x;
}
printf("%.2lf",(res*0.65-1)*2);
return 0;
}
A1014
#include<iostream>
#include<queue>
#include<unordered_map>
using namespace std;
const int maxn=22;
queue<int> q[maxn];
int sum[maxn];
int n,m,k,Q;
int main()
{
cin >> n >> m >> k >> Q;
unordered_map<int,int>hash;
for(int i=1; i<=k; i++)
{
int s;
cin >> s;
int t=0;
for(int j=0; j<n; j++)
{
if(i<=n*m)
{
if(q[j].size()<q[t].size())
t=j;
}
else
if(q[j].front()<q[t].front())
t=j;
}
sum[t]+=s;
if(i>n*m)
q[t].pop();
q[t].push(sum[t]);
if(sum[t]-s<540)
hash[i]=sum[t];
}
int temp;
while(Q--)
{
cin >> temp;
if(hash.count(temp))
{
printf("%02d:%02d\n",hash[temp]/60+8,hash[temp]%60);
}
else
cout << "Sorry" << endl;
}
return 0;
}
A1031

#include<iostream>
using namespace std;
string s;
int n1,n2,n3;
int main()
{
cin >> s;
n1=(s.size()+2)/3;
n3=n1;
n2=s.size()-n1*2;
int k=0;
char a[s.size()][s.size()];
for(int i=0; i<s.size(); i++)
for(int j=0; j<s.size(); j++)
a[i][j]=' ';
for(int i=0; i<n1; i++)
{
a[i][0]=s[k++];
}
for(int i=1; i<=n2; i++)
{
a[n1-1][i]=s[k++];
}
for(int i=n1-1; i>=0; i--)
{
a[i][n2+1]=s[k++];
}
for(int i=0; i<n1; i++)
{
for(int j=0; j<=n2+1; j++)
{
if(a[i][j]!=' ')
cout << a[i][j];
else if(a[i][j]==' ')
cout << ' ';
}
cout << endl;
}
}
A1041
#include<iostream>
using namespace std;
const int maxn=100010;
int flag[maxn];
int a[maxn];
int n;
int main()
{
cin >> n;
for(int i=0; i<n; i++)
{
cin >> a[i];
flag[a[i]]++;
}
for(int i=0; i<n; i++)
{
if(flag[a[i]]==1)
{
cout << a[i];
return 0;
}
}
cout << "None";
return 0;
}
A1042
#include <iostream>
#include <cstring>
using namespace std;
const int N = 60;
int k;
int q[N], p[N], w[N];
void print(int x)
{
if (x <= 13) cout << 'S' << x;
else if (x <= 26) cout << 'H' << x - 13;
else if (x <= 39) cout << 'C' << x - 26;
else if (x <= 52) cout << 'D' << x - 39;
else cout << 'J' << x - 52;
}
int main()
{
cin >> k;
for (int i = 1; i <= 54; i ++ ) cin >> q[i];
for (int i = 1; i <= 54; i ++ ) p[i] = i;
while (k -- )
{
memcpy(w, p, sizeof w);
for (int i = 1; i <= 54; i ++ ) p[q[i]] = w[i];
}
for (int i = 1; i <= 54; i ++ )
{
print(p[i]);
if (i != 54) cout << ' ';
}
return 0;
}
A1047
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int maxn=40010;
vector<string> lesson[maxn];
int n,k;
int main()
{
scanf("%d%d", &n, &k);
char str[5];
while (n -- )
{
int cnt;
scanf("%s%d", str, &cnt);
while (cnt -- )
{
int l;
scanf("%d", &l);
lesson[l].push_back(str);
}
}
for(int T=1; T<=k; T++)
{
cout << T << " " << lesson[T].size() << endl;
sort(lesson[T].begin(),lesson[T].end());
for(auto id:lesson[T])
printf("%s\n",id.c_str());
}
return 0;
}
A1054
#include<iostream>
#include<unordered_map>
using namespace std;
int n,m;
int main()
{
cin >> m >> n;
unordered_map<int,int> mp;
for(int i=0; i<m*n; i++)
{
int x;
cin >> x;
if(++mp[x]>n*m/2)
{
cout << x;
break;
}
}
return 0;
A1062
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=100010;
struct node
{
int id,v,t,level;
int total() const
{
return v+t;
}
bool operator < (const node &t) const
{
if(level != t.level)
return level<t.level;
if(total() != t.total())
return total()>t.total();
if(v!=t.v)
return v>t.v;
if(id!=t.id)
return id<t.id;
}
}Node[maxn];
int n,l,h;
int main()
{
cin >> n >> l >> h;
int idd,temp1,temp2;
int k=0;
while(n--)
{
cin >> idd >> temp1 >> temp2;
if(temp1<l || temp2<l)
continue;
int level;
if(temp1>=h && temp2>=h)
level=1;
else if(temp1>=h && temp2<h)
level=2;
else if(temp1<h && temp2<h && temp1>=temp2)
level=3;
else
level=4;
Node[k++]={idd,temp1,temp2,level};
}
sort(Node,Node+k);
cout << k << endl;
for(int i=0; i<k; i++)
printf("%08d %d %d\n",Node[i].id,Node[i].v,Node[i].t);
return 0;
}
A1065
#include<iostream>
using namespace std;
typedef long long LL;
bool check(LL a,LL b,LL c)
{
LL d=a+b;
if(a>=0 && b>=0 && d<0)
return true;
if(a<0 && b<0 && d>=0)
return false;
return a+b>c;
}
int main()
{
int n;
cin >> n;
LL a,b,c,d;
for(int T=1; T<=n; T++)
{
scanf("%lld%lld%lld",&a,&b,&c);
if(check(a,b,c))
printf("Case #%d: true\n",T);
else
printf("Case #%d: false\n",T);
}
}
A1069
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
string s;
cin >> s;
s.insert(0,4-s.length(),'0');
while(1)
{
sort(s.begin(),s.end());
string smin=s;
int minn=stoi(smin);
reverse(s.begin(),s.end());
string smax=s;
int maxn=stoi(smax);
int n= maxn-minn;
printf("%04d - %04d = %04d\n",maxn,minn,n);
if(n==0 || n==6174)
break;
s=to_string(n);
s.insert(0,4-s.length(),'0');
}
return 0;
}
A1080
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
const int maxn=40010;
int n,m,k;
int cnt[maxn];
vector<int> uty[maxn];
int wish[maxn];
struct node
{
int ge,gi,id;
int wish[5];
int total() const
{
return ge+gi;
}
bool operator <(node &t) const
{
if(total()!=t.total())
{
return total()>t.total();
}
return ge>t.ge;
}
bool operator == (node &t) const
{
return ge==t.ge && gi==t.gi;
}
}Node[maxn];
int main()
{
cin >> n >> m >> k;
for(int i=0; i<m; i++)
cin >> cnt[i];
for(int i=0; i<n; i++)
{
scanf("%d %d",&Node[i].ge,&Node[i].gi);
Node[i].id=i;
for(int j=0; j<k; j++)
{
cin >> Node[i].wish[j];
}
}
sort(Node,Node+n);
memset(wish,-1,sizeof wish);
for(int i=0; i<n; )
{
int j=i+1;
while(j<n && Node[i]==Node[j])
j++;
for(int t=i; t<j; t++)
for(int u=0; u<k; u++)
{
if(cnt[Node[t].wish[u]]>uty[Node[t].wish[u]].size())
{
wish[t]=Node[t].wish[u];
break;
}
}
for(int t=i; t<j; t++)
{
if(wish[t]!=-1)
uty[wish[t]].push_back(Node[t].id);
}
i=j;
}
for(int i=0; i<m; i++)
{
if(uty[i].size())
{
sort(uty[i].begin(),uty[i].end());
printf("%d",uty[i][0]);
for(int j=1; j<uty[i].size(); j++)
printf(" %d",uty[i][j]);
}
cout << endl;
}
}
A1083
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1000;
struct node
{
string name;
string id;
int grade;
bool operator<(const node &t)
{
if(grade!=t.grade)
{
return grade>t.grade;
}
}
}Node[maxn];
int n;
int low,high;
int main()
{
cin >> n;
string temp1,temp2;
int temp3;
for(int i=0; i<n; i++)
{
cin >> temp1 >> temp2 >> temp3;
Node[i]={temp1,temp2,temp3};
}
cin >> low >> high;
sort(Node,Node+n);
bool flag=false;
for(int i=0; i<n; i++)
{
if(Node[i].grade>=low && Node[i].grade<=high)
{
flag=true;
cout << Node[i].name << " " << Node[i].id << endl;
}
}
if(flag==false)
cout << "NONE" << endl;
return 0;
}
A1092
#include<iostream>
#include<unordered_map>
using namespace std;
string temp1,temp2;
int main()
{
unordered_map<char,int> aa;
cin >> temp1 >> temp2;
for(int i=0; i<temp1.size(); i++)
{
aa[temp1[i]]++;
}
for(int i=0; i<temp2.size(); i++)
{
aa[temp2[i]]--;
}
int yes=0,no=0;
for(auto t:aa)
{
if(t.second>0)
yes+=t.second;
else
no+=t.second;
}
if(no<0)
cout << "No" << " " << -no;
else
cout << "Yes" << " " << yes;
return 0;
}
A1095
#include <iostream>
#include <cstring>
#include <algorithm>
#include <unordered_map>
#include <vector>
using namespace std;
struct Event
{
int tm, status;
bool operator< (const Event &t) const
{
return tm < t.tm;
}
};
int get(vector<Event>& ets)
{
int res = 0;
for (int i = 0; i < ets.size(); i += 2)
res += ets[i + 1].tm - ets[i].tm;
return res;
}
int main()
{
int n, m;
scanf("%d%d", &n, &m);
unordered_map<string, vector<Event>> cars;
char id[20], status[20];
for (int i = 0; i < n; i ++ )
{
int hh, mm, ss;
scanf("%s %d:%d:%d %s", id, &hh, &mm, &ss, status);
int t = hh * 3600 + mm * 60 + ss;
int s = 0;
if (status[0] == 'o') s = 1;
cars[id].push_back({t, s});
}
vector<Event> events;
for (auto& item : cars)
{
auto& ets = item.second;
sort(ets.begin(), ets.end());
int k = 0;
for (int i = 0; i < ets.size(); i ++ )
if (ets[i].status == 0)
{
if (i + 1 < ets.size() && ets[i + 1].status == 1)
{
ets[k ++ ] = ets[i];
ets[k ++ ] = ets[i + 1];
i ++ ;
}
}
ets.erase(ets.begin() + k, ets.end());
for (int i = 0; i < k; i ++ ) events.push_back(ets[i]);
}
sort(events.begin(), events.end());
int k = 0, sum = 0;
while (m -- )
{
int hh, mm, ss;
scanf("%d:%d:%d", &hh, &mm, &ss);
int t = hh * 3600 + mm * 60 + ss;
while (k < events.size() && events[k].tm <= t)
{
if (events[k].status == 0) sum ++ ;
else sum -- ;
k ++ ;
}
printf("%d\n", sum);
}
int maxt = 0;
for (auto& item : cars) maxt = max(maxt, get(item.second));
vector<string> aaa;
for(auto &item:cars)
{
if(get(item.second)==maxt)
aaa.push_back(item.first);
}
sort(aaa.begin(),aaa.end());
for(int i=0; i<aaa.size(); i++)
printf("%s ",aaa[i].c_str());
printf("%02d:%02d:%02d",maxt/3600,maxt%3600/60,maxt%60);
return 0;
}
A1105
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=10010;
int a[maxn],er[maxn][maxn];
int n;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
cin >> n;
for(int i=0; i<n; i++)
cin >> a[i];
if(n==1)
{
cout << a[0];
return 0;
}
sort(a,a+n,cmp);
int M=ceil(sqrt(n));
while(n%M!=0)
M++;
int N=n/M;
int nai=1,zi=M,pi=1,gu=N,i=1,j=1;
int num=0;
while(num<n)
{
while(j<gu && num<n)
{
er[i][j]=a[num++];
j++;
}
while(i<zi && num<n)
{
er[i][j]=a[num++];
i++;
}
while(j>pi && num<n)
{
er[i][j]=a[num++];
j--;
}
while(i>nai && num<n)
{
er[i][j]=a[num++];
i--;
}
nai+=1;
zi-=1;
pi+=1;
gu-=1;
i++;
j++;
if(num==n-1)
{
er[i][j]=a[num++];
}
}
for(int i=1; i<=M; i++)
{
for(int j=1; j<=N; j++)
{
if(j!=1)
cout << " ";
cout << er[i][j];
}
cout << endl;
}
return 0;
}
A1109
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=10010;
int n,k;
struct node
{
string name;
int height;
}Node[maxn];
bool cmp(node a,node b)
{
if(a.height!=b.height)
return a.height>b.height;
return a.name<b.name;
}
int main()
{
cin >> n >> k;
for(int i=0; i<n; i++)
{
cin >> Node[i].name >> Node[i].height;
}
sort(Node,Node+n,cmp);
int j=0;
for(int i=0; i<k; i++)
{
int renshu=n/k;
if(i==0)
{
renshu+=n%k;
}
string temp[maxn];
for(int r=renshu/2+1,l=r-1; r<=renshu || l>0; r++,l--)
{
if(r<=renshu)
temp[r]=Node[j++].name;
if(l>0)
temp[l]=Node[j++].name;
}
for(int s=1; s<=renshu; s++)
{
if(s!=1)
cout << " ";
cout << temp[s];
}
cout << endl;
}
}
A1128

#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1010;
int n;
int main()
{
cin >> n;
bool row[maxn],zhu[maxn*2],fu[maxn*2];
while(n--)
{
memset(row,false,sizeof(row));
memset(zhu,false,sizeof(zhu));
memset(fu,false,sizeof(fu));
int temp1;
cin >> temp1;
bool success=true;
for(int i=0; i<temp1; i++)
{
int temp2;
cin >> temp2;
if(row[temp2] || zhu[i-temp2+temp1] || fu[i+temp2])
success=false;
row[temp2]= zhu[i-temp2+temp1]=fu[i+temp2]=true;
}
if(success)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return 0;
}
A1129
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=50010;
int ans[maxn]={0};
int top_k[maxn];
bool cmp(int a,int b)
{
if(ans[a]!=ans[b])
return ans[a]>ans[b];
return a<b;
}
int main()
{
int n,m;
cin >> n >> m;
int k=0,id;
for(int i=0; i<n; i++)
{
cin >> id;
if(i!=0)
{
cout << id << ":";
for(int i=0; i<k; i++)
{
cout << " " << top_k[i];
}
cout << endl;
}
ans[id]++;
bool flag=false;
for(int j=0; j<k; j++)
{
if(top_k[j]==id)
{
flag=true;
break;
}
}
if(flag==false)
{
top_k[k++]=id;
}
sort(top_k,top_k+k,cmp);
k=min(k,m);
}
}
A1132
#include<iostream>
using namespace std;
int n;
int main()
{
cin >> n;
string temp1,temp2,temp3;
int temp4,temp5,temp6;
while(n--)
{
cin >> temp1;
temp2=temp1.substr(0,temp1.size()/2);
temp3=temp1.substr(temp1.size()/2);
temp4=stoi(temp2);
temp5=stoi(temp3);
temp6=stoi(temp1);
if(temp4*temp5 && temp6%(temp4*temp5)==0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
A1147
#include<iostream>
using namespace std;
const int maxn=1010;
int n,m;
int h[maxn];
void postOrder(int root)
{
if(root>n)
return ;
postOrder(2*root);
postOrder(2*root+1);
cout <<h[root];
if(root!=1)
cout << " ";
}
int main()
{
cin >> m >> n;
while(m--)
{
for(int i=1; i<=n; i++)
cin >> h[i];
bool lt=false,gt=false;
for(int i=1; i<=n; i++)
{
for(int j=0; j<2; j++)
{
if(i*2+j<=n)
{
int a=h[i],b=h[i*2+j];
if(a>b)
gt=true;
else
lt=true;
}
}
}
if(gt && lt)
{
cout << "Not Heap" << endl;
}
else if(gt)
cout << "Max Heap" << endl;
else
cout << "Min Heap" << endl;
postOrder(1);
cout << endl;
}
}