contents:
A. Windblume Ode
题意
A bow adorned with nameless flowers that bears the earnest hopes of an equally nameless person.
You have obtained the elegant bow known as the Windblume Ode. Inscribed in the weapon is an array of n (n≥3) positive distinct integers (i.e. different, no duplicates are allowed).
Find the largest subset (i.e. having the maximum number of elements) of this array such that its sum is a composite number. A positive integer x is called composite if there exists a positive integer y such that 1<y<x and x is divisible by y.
If there are multiple subsets with this largest size with the composite sum, you can output any of them. It can be proven that under the constraints of the problem such a non-empty subset always exists.
n个数,每个数都不同,你可以从中删除一些元素,使得总和不是素数
n(3~100)
思路
n的个数为三,则sum>=6
考虑和为偶数时一个数都不用删
和为奇数的时候,则其中至少有一个元素为奇数
可以删除那个元素
meAC
#include <bits/stdc++.h>
using namespace std;
int arr[107];
bool isprime(int x)
{
for (int i = 2; i * i <= x;i++)
{
if(x%i==0) return 0;
}
return 1;
}
int main()
{
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int sum = 0;
for (int i = 1; i <= n; i++)
{
cin >> arr[i];
sum += arr[i];
}
if (isprime(sum))
{
cout << n - 1 << endl;
int index1 = 1;
while (1)
{
if (arr[index1] & 1)
{
break;
}
index1++;
}
for (int i = 1; i <= n; i++)
{
if (i == index1)
continue;
cout << i << " ";
}
cout << endl;
}
else
{
cout << n << endl;
for (int i = 1; i <= n; i++)
cout << i << " ";
cout << endl;
}
}
}
B. Omkar and Heavenly Tree
题意
n个点,n-1条关系
关系:
a,b,c
b不能在ac最短路径上
思路
菊花图
n个点,n-1条,总有一个点是关系里面没有做过b的点
AC
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int, int>
#define psi pair<string, int>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define ld long double
const int N = 1E5 + 7;
#define INF ~0ULL
int vis[N];
int main()
{
int t;
cin >> t;
int n, m;
int a, b, c;
while (t--)
{
memset(vis,0,sizeof(vis));
cin >> n >> m;
for (int i = 1; i <= m; i++)
{
cin>>a>>b>>c;
vis[b]++;
}
int dex =1;
while(1){
if(vis[dex]==0){
break;
}
dex++;
}
for(int i=1;i<=n;i++){
if(i==dex) continue;
cout<<dex<<" "<<i<<endl;
}
}
}
C. Omkar and Determination
链接: 大佬博客.
D. Omkar and the Meaning of Life
这是特别有意思的题
链接: link.