解题报告8VC Venture Cup 2017 - Elimination Round
题目链接:http://codeforces.com/contest/755
本蒟蒻做了半天只会做前两道题。。
A. PolandBall and Hypothesis
题意:给出n,让你找出一个m,使n*m+1不是素数。
数据很小,直接暴力枚举。
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std ;
bool prime( int n )
{
for( int i = 2 ; i <= sqrt(n) ; i++)
if( n % i == 0 )
return false;
return true;
}
int main()
{
int n ;
cin >> n ;
for( int i = 1 ; i <= 1000 ; i++)
{
if( ! prime( n*i + 1 ) )
{
cout << i << endl ;
return 0 ;
}
}
return 0 ;
}
第二题:
题意 :给出n,m 表示每个人拥有的单词数, 然后给出每个人的单词, 现在从第一个人开始每次说一个自己有单词, 不能出现重复的, 谁说不了了就输了。
第一次提交:
把 两个人重复的去掉之后比大小,若第一个人大于等于第二个人则YES,否则NO。
WA了。因为没考虑到
3 3
a
a
c
a
a
b
这种一样的会是偶数的情况。所以在去重之后要分奇偶
#include<cstring>
#include<cmath>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
string a[1010] , b[1010];
int n , m ;
cin >> n >> m ;
for( int i = 1 ; i <= n ; i++)
cin >> a[i] ;
for( int i = 1 ; i <= m ; i++)
cin >> b[i] ;
int diff = 0 ;
for( int i = 1 ; i <= m ; i++)
{
for( int j = 1 ; j <= n ; j++)
{
if( b[i] == a[j] )
diff++;
}
}
n = n - diff , m = m - diff ;
if( n > m )
cout << "YES" << endl;
else if ( n == m )
{
if( diff % 2 == 1 )
cout << "YES" <<endl;
else
cout <<"NO" << endl ;
}
else
cout << "NO"<<endl ;
return 0 ;
}
看到有人用map去重。STL还是不太会呢,MAP去重应该比我高好多,索性题目数据小。
第三题
题读了半天勉强读懂了,然而相关算法不知道是什么。。
浙公网安备 33010602011771号