RCC 2014 Warmup (Div. 2) A~C(二)

2014-11-24 11:58:46 · 作者: · 浏览: 1
tain YES if the data is in chronological order, and NO otherwise.
Sample test(s)
input
2
0 1
1 1
output
YES
input
4
0 1
1 2
1 1
0 2
output
NO
input
4
0 1
1 1
0 1
0 2
output
YES
排序乱搞。。。
[cpp]
#include
#include
#include
#include
using namespace std;
struct ooxx
{
int x,y,id;
}a[110000];
bool cmpA(ooxx a,ooxx b)
{
if(a.y!=b.y) return a.y
return a.id
}
int n;
int main()
{
scanf("%d",&n);
for(int i=0;i
{
scanf("%d%d",&a[i].x,&a[i].y);
a[i].id=i;
}
sort(a,a+n,cmpA);
bool flag=true;
int last=-1,eb=-1;
for(int i=0;i
{
if(last!=a[i].y)
{
last=a[i].y; eb=0;
if(a[i].x!=0) flag=false;
}
else
{
if(a[i].x<=eb) continue;
else if(a[i].x==eb+1) eb++;
else flag=false;
}
}
if(flag==false) puts("NO");
else puts("YES");
return 0;
}
C. Football
time limit per test 1 second
memory limit per test 256 megabytes
input standard input
output standard output
One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided inton teams and played several matches, two teams could not play against each other more than once.
The appointed Judge was the most experienced member — Pavel. But since he was the wisest of all, he soon got bored of the game and fell asleep. Waking up, he discovered that the tournament is over and the teams want to know the results of all the matches.
Pavel didn't want anyone to discover about him sleeping and not keeping an eye on the results, so he decided to recover the results of all games. To do this, he asked all the teams and learned that the real winner was friendship, that is, each team beat the other teams exactly k times. Help Pavel come up with chronology of the tournir that meets all the conditions, or otherwise report that there is no such table.
Input
The first line contains two integers — n and k (1 ≤ n, k ≤ 1000).
Output
In the first line print an integer m — number of the played games. The following m lines should contain the information about all the matches, one match per line. The i-th line should contain two integers ai and bi (1 ≤ ai, bi ≤ n; ai ≠ bi). The numbers ai and bi mean, that in the i-th match the team with number ai won against the team with number bi. You can assume, that the teams are numbered from1 to n.
If a tournir that meets the conditions of the problem does not exist, then print -1.
Sample test(s)
input
3 1
output
3
1 2
2 3
3 1
隔k个数,连一条边。。。。 输出很多,卡CIN,COUT
[cpp]
#include
#include
#include
#include
#include
using namespace std;
typedef pair pII;
int indegree[2000];
bool ck[1100][1100];
int n,k;
vector ans;
int main()
{
cin>>n>>k;
for(int l=1;l<=k;l++)
{
for(int i=0;i
{
int j=(i+l)%n;
if(indegree[j]+1>k||j==i||ck[i][j]||ck[j][i])
{
puts("-1"); return 0;
}
else
{
indegree[j]++;
ck[i][j]=ck[j][i]=1;
ans.push_back(make_pair(i,j));
}
}
}
int sz=ans.size(