【PAT甲级】1056 Mice and Rice (25 分)

题意:

输入两个正整数N和M(<=1000),接着输入两行,每行N个数,第一行为每只老鼠的重量,第二行为每只老鼠出战的顺序。输出它们的名次。(按照出战顺序每M只老鼠分为一组,剩余不足M只为一组,每组只能有一个胜者,其他老鼠排名均为这一轮胜者数量+1)

代码:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1007],b[1007];
int num;
int ans[1007];
int c[1007],d[1007];
pair<int,int>e[1007];
int flag;
bool vis[1007];
void contest(){
int cnt=0;
int round=0;
int no=0;
for(int i=1;i<=num;++i){
c[++cnt]=b[i];
if(cnt==m||i==num){
++round;
int mx=a[c[1]],pos=c[1];
for(int j=2;j<=cnt;++j){
if(a[c[j]]>mx){
mx=a[c[j]];
pos=c[j];
}
}
for(int j=1;j<=cnt;++j)
if(c[j]==pos)
d[++no]=c[j];
else
vis[c[j]]=1;
cnt=0;
}
}
for(int i=1;i<=num;++i)
if(!ans[b[i]]&&vis[b[i]])
ans[b[i]]=round+1;
if(round==1){
ans[d[1]]=1;
flag=1;
}
for(int i=1;i<=no;++i)
b[i]=d[i];
num=no;
no=0;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(int i=1;i<=n;++i)
cin>>a[i];
for(int i=1;i<=n;++i){
cin>>b[i];
++b[i];
}
num=n;
while(!flag)
contest();
cout<<ans[1];
for(int i=2;i<=n;++i)
cout<<" "<<ans[i];
return 0;
}

原文地址:https://www.cnblogs.com/ldudxy/p/11674701.html

时间: 2024-10-08 05:10:25

【PAT甲级】1056 Mice and Rice (25 分)的相关文章

PAT 1056 Mice and Rice (25)

Mice and Rice is the name of a programming contest in which each programmer must write a piece of code to control the movements of a mouse in a given map. The goal of each mouse is to eat as much rice as possible in order to become a FatMouse. First

PAT 甲级 1040 Longest Symmetric String (25 分)(字符串最长对称字串,遍历)

1040 Longest Symmetric String (25 分) Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you must output 11. In

PAT 甲级 1083 List Grades (25 分)

1083 List Grades (25 分) Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of which the grades are in a given interval. I

PAT 甲级 1013 Battle Over Cities (25 分)(图的遍历,统计强连通分量个数,bfs,一遍就ac啦)

1013 Battle Over Cities (25 分) It is vitally important to have all the cities connected by highways in a war. If a city is occupied by the enemy, all the highways from/toward that city are closed. We must know immediately if we need to repair any oth

PAT 甲级 1036 Boys vs Girls (25 分)(简单题)

1036 Boys vs Girls (25 分) This time you are asked to tell the difference between the lowest grade of all the male students and the highest grade of all the female students. Input Specification: Each input file contains one test case. Each case contai

PAT 甲级 1052 Linked List Sorting (25 分)(数组模拟链表,没注意到不一定所有节点都在链表里)

1052 Linked List Sorting (25 分) A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. Now given a linked list, y

PAT 甲级 1060 Are They Equal (25 分)(科学计数法,接连做了2天,考虑要全面,坑点多,真麻烦)

1060 Are They Equal (25 分) If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0 with simple chopping. Now given the number of significant digits on a machine and two

PAT (Advanced Level) 1056. Mice and Rice (25)

简单模拟. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> #include<cstdio> #include<map> #include<queue> #include<string> #include<stack> #include<vector> using namespace std

【PAT甲级】1101 Quick Sort (25 分)

题意: 输入一个正整数N(<=1e5),接着输入一行N个各不相同的正整数.输出可以作为快速排序枢纽点的个数并升序输出这些点的值. trick: 测试点2格式错误原因:当答案为0时,需要换行两次??.....这是为何 AAAAAccepted code: 1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 int a[100007]; 5 int b[100007]; 6 int