对里面的每个数字的位置进行查找
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(3)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
vector vec[105];
int main(){
fio;
int n, c, x;
cin >> n >> c;
for(int i = 1; i <= n; ++i) {
cin >> x;
vec[x].push_back(i);
}
int ans = 0;
for(int i = 1; i <= c; ++i) {
for(int j = 1; j <= c; ++j) {
if(i == j) continue;
int len1 = vec[i].size();
int len2 = vec[j].size();
int st1 = 0, st2 = 0, temp = 0, sum = 0;
while(1) {
while(st1 < len1 && vec[i][st1] < temp) {
st1 += 1;
}
if(st1 == len1) break;
temp = vec[i][st1];
sum += 1;
while(st2 < len2 && vec[j][st2] < temp) {
st2 += 1;
}
if(st2 == len2) break;
sum += 1;
temp = vec[j][st2];
}
ans = max(ans, sum);
}
}
cout << ans << endl;
return 0;
}
乘法原理
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(6)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
int a[26];
int main(){
fio;
int n;
string dest;
while(cin >> n) {
memset(a, 0, sizeof(a));
cin >> dest;
for(int i = 0; i < n; ++i) {
a[dest[i] - 'a'] += 1;
}
if(!a[0] || !a['v' - 'a'] || !a['i' - 'a'] || !a['n' - 'a']) {
cout << "0/1" << endl;
} else {
int t = pow(n, 4), k = 1, gcd;
k = a[0] * a['v' - 'a'] * a['i' - 'a'] * a['n' - 'a'];
gcd = __gcd(k, t);
cout << k / gcd << "/" << t / gcd << endl;
}
}
return 0;
}
东西方向的先走,然后在南北里面找是不是有时间冲突,有的话就等待。
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(3)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
int a[1005];
int b[1005];
int vis[1005];
int main(){
fio;
int n, m;
while(cin >> n >> m) {
memset(vis, 0, sizeof(vis));
for(int i = 0; i < n; ++i) cin >> a[i], vis[a[i]] = 1;
for(int i = 0; i < m; ++i) cin >> b[i];
for(int i = 0; ; ++i) {
int flag = 0;
for(int j = 0; j < m; ++j) {
if(vis[b[j] + i] == 1) {
flag = 1;
break;
}
}
if(flag == 0) {
cout << i << endl;
break;
}
}
}
return 0;
}
区间概率没搞懂咋算的,但是记得好像是个结论题。
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(6)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
LL quick_pow(LL a, LL b) {
LL sum = 1;
while(b) {
if(b & 1) sum = sum * a % mod;
a = a * a % mod;
b >>= 1;
}
return sum;
}
int main(){
fio;
LL n;
while(cin >> n) {
cout << (n + 1) * quick_pow(2 * n, mod - 2) % mod << endl;
}
return 0;
}
/*
结论题
(n + 1) / 2n
用逆元处理一下
*/
第三位小数有两种情况:
t <= 4 sum += -t * 0.001
t >= 5 sum += (10 - t) * 0.001
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(3)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
int main(){
fio;
int n;
while(cin >> n) {
double sum = 0.0;
for(int i = 0; i < n; ++i) {
string dest;
int k = 0;
cin >> dest;
for(int j = 0; j < dest.size(); ++j) {
if(dest[j] == '.') {
k = j;
break;
}
}
int t = dest[k + 3] - '0';
if(t <= 4) {
sum += -t * 0.001;
} else {
sum += (10 - t) * 0.001;
}
}
cout << fix << sum << endl;
}
return 0;
}
按比例分配就可以了。
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(6)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
LL a[1005];
int main(){
fio;
LL n, m;
while(cin >> n >> m) {
LL lcm = 1, sum = 0;
for(int i = 0; i < n; ++i) {
cin >> a[i];
lcm = lcm * a[i] / __gcd(lcm, a[i]);
}
for(int i = 0; i < n; ++i) {
sum += lcm / a[i];
}
if(m % sum) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
for(int i = 0; i < n; ++i) {
cout << m / sum * lcm / a[i];
if(i != n - 1) cout << " ";
else cout << endl;
}
}
}
return 0;
}
#include
#include
#include
#include
#define LL long long
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fix fixed << setprecision(6)
using namespace std;
int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const double PI = 45.0 / atan(1.0);
int main(){
fio;
int x, y, a, b;
cin >> x >> y;
a = (x + y) / 2;
b = (x - y) / 2;
cout << a * b << endl;
return 0;
}