T1
#include <bits/stdc++.h>
using namespace std;
bool isPerfectSquare(int n)
{
int root = sqrt(n);
return root * root == n;
}
int main()
{
int n;
cin >> n;
if(isPerfectSquare(n))
{
cout << n;
return 0;
}
for(int i = n/2; i >= 1; i--)
{
if(0 == n % i && isPerfectSquare(i))
{
cout << i;
break;
}
}
return 0;
}
T2
#include <bits/stdc++.h>
using namespace std;
bool isPerfectSquare(int n)
{
int root = sqrt(n);
return root * root == n;
}
int main()
{
int n;
cin >> n;
if(isPerfectSquare(n))
{
cout << n;
return 0;
}
for(int i = n/2; i >= 1; i--)
{
if(0 == n % i && isPerfectSquare(i))
{
cout << i;
break;
}
}
return 0;
}
T3
#include <bits/stdc++.h>
using namespace std;
const int maxM = 1005;
struct course
{
string className;
int capacity;
}cour[maxM];
int main()
{
int m, n;
cin >> m >> n;
for(int i = 1; i <= m; i++)
{
cin >> cour[i].className >> cour[i].capacity;
}
map<string, int> cnt;
string name;
for(int i = 1; i <= n; i++)
{
cin >> name;
cnt[name]++;
}
int classCnt = 0, studentCnt = 0;
for(int i = 1; i <= m; i++)
{
if(cnt[cour[i].className] * 2 < cour[i].capacity)
{
classCnt++;
studentCnt += cnt[cour[i].className];
}
else if(cnt[cour[i].className] > cour[i].capacity)
{
studentCnt += cnt[cour[i].className] - cour[i].capacity;
}
}
cout << classCnt << endl << studentCnt;
return 0;
}
T4
#include <iostream>
using namespace std;
int main()
{
string s;
cin >> s;
int len = s.size();
for(int i = 0; i < len - 1; i++)
{
if(s[i] == s[i + 1] || s[i] == s[i + 2])
{
cout << "Not a random string";
return 0;
}
}
cout << "Random string";
return 0;
}
T5
#include <iostream>
using namespace std;
const int mod = 1e9 + 9;
const int maxN = 1e6 + 5;
int dp[maxN];
int main()
{
int n;
cin >> n;
dp[0] = 1;
dp[1] = 2;
for(int i = 2; i <= n; i++)
{
dp[i] = (dp[i - 1] + dp[i - 2] ) % mod;
}
cout << dp[n];
return 0;
}
==============================
长按识别二维码加好友邀请进信息学竞赛群