A1125
#include<iostream>
using namespace std;
const int maxn=1010;
int n,m;
int a[maxn];
int ans;
void postOrder(int root)
{
if(root>n)
return ;
postOrder(root*2);
postOrder(root*2+1);
cout << a[root];
ans++;
if(ans<n)
cout << " ";
}
int main()
{
cin >> m >> n;
while(m--)
{
for(int i=1; i<=n; i++)
{
cin >> a[i];
}
ans=0;
bool lt=false,gt=false;
for(int i=1; i<=n; i++)
{
for(int j=0; j<2; j++)
{
int gen=a[i],zi=a[i*2+j];
if(i*2+j<=n)
{
if(gen>zi)
{
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;
}
}
A1140
#include<iostream>
using namespace std;
string s;
int n,m;
int main()
{
cin >> m >> n;
s=to_string(m);
for(int i=0; i<n-1; i++)
{
string next;
for(int j=0; j<s.size();)
{
int k=j+1;
while(k<s.size() && s[j]==s[k])
{
k++;
}
next+=s[j]+to_string(k-j);
j=k;
}
s=next;
}
cout << s;
}
A1132
#include<iostream>
using namespace std;
int n;
string s;
int main()
{
cin >> n;
string temp1,temp2;
int temp3,temp4;
double origin;
for(int i=0; i<n; i++)
{
cin >> s;
temp1=s.substr(0,s.size()/2);
temp2=s.substr(s.size()/2);
temp3=stoi(temp1);
temp4=stoi(temp2);
origin=stoi(s);
double result=origin/temp3/temp4;
if(result-(int)result==0)
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 n,m,k;
int top_k[11];
bool cmp(int x,int y)
{
if(ans[x]!=ans[y])
{
return ans[x]>ans[y];
}
return x<y;
}
int main()
{
cin >> n >> m;
int id;
k=0;
for(int i=0; i<n; i++)
{
cin >> id;
if(i!=0)
{
cout << id << ":";
for(int j=0; j<k; j++)
{
cout << " " << top_k[j];
}
cout << endl;
}
ans[id]++;
bool flag=false;
for(int j=0; j<k; j++)
{
if(top_k[j]==id)
flag=true;
}
if(!flag)
top_k[k++]=id;
sort(top_k,top_k+k,cmp);
k=min(k,m);
}
return 0;
}
A1128
#include<iostream>
#include<cstring>
using namespace std;
const int maxn=1111;
bool row[maxn],zhu[maxn*2],fu[maxn*2];
int n;
int main()
{
cin >> n;
int temp1;
while(n--)
{
memset(row,false,sizeof(row));
memset(zhu,false,sizeof(zhu));
memset(fu,false,sizeof(fu));
cin >> temp1;
int temp2;
bool success=true;
for(int y=1; y<=temp1; y++)
{
int x;
cin >> x;
if(row[x] || zhu[y-x+temp1] || fu[x+y])
success=false;
row[x]=zhu[y-x+temp1]=fu[x+y]=true;
}
if(success==true)
{
cout << "YES" << endl;
}
else
cout << "NO" << endl;
}
return 0;
}
A1121
#include<iostream>
#include<map>
#include<set>
using namespace std;
const int maxn=99999;
map<int,int> ss;
int n,m;
int main()
{
cin >> n;
int temp1,temp2;
for(int i=0; i<n; i++)
{
cin >> temp1 >> temp2;
ss[temp1]=temp2;
ss[temp2]=temp1;
}
cin >> m;
set<int> people;
int temp3;
for(int i=1; i<=m; i++)
{
cin >> temp3;
people.insert(temp3);
}
for(set<int>::iterator it=people.begin(); it!=people.end(); it++)
if(people.find(ss[*it])!=people.end())
{
people.erase(ss[*it]);
people.erase(*it);
}
cout << people.size() << endl;
for(set<int>::iterator it=people.begin(); it!=people.end(); it++)
{
if(it!=people.begin())
cout << " ";
printf("%05d",*it);
}
return 0;
}
A1109
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
const int maxn=10011;
struct node
{
string name;
int height;
}Node[maxn],Node1[maxn];
int n,k;
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;
string temp1;
for(int i=0; i<n; i++)
{
cin >> Node[i].name >> Node[i].height;
}
sort(Node,Node+n,cmp);
for(int i=0,j=0; i<k; i++)
{
int len=n/k;
if(!i)
{
len=n/k+n%k;
}
for(int r=len/2+1,l=r-1; r<=len || l>0; r++,l--)
{
if(r<=len)
{
Node1[r]=Node[j++];
}
if(l>0)
Node1[l]=Node[j++];
}
for(int s=1; s<=len; s++)
{
if(s!=1)
cout << " ";
cout << Node1[s].name;
}
cout << endl;
}
}