题解,超星进程
A - Geometric Progression
思路:矩阵快速幂
构造[1,c]*[f(n-1)]
[0,c] [c^(n-2)]
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
typedef long long ll;
ll a, x, MOD;
struct matrix
{
ll a1, a2, b1, b2;
matrix(ll a1, ll a2, ll b1, ll b2) : a1(a1), a2(a2), b1(b1), b2(b2) {}
matrix operator*(const matrix& y)
{
matrix ans((a1 * y.a1 + a2 * y.b1) % MOD,
(a1 * y.a2 + a2 * y.b2) % MOD,
(b1 * y.a1 + b2 * y.b1) % MOD,
(b1 * y.a2 + b2 * y.b2) % MOD);
return ans;
}
};
matrix qpow(matrix a, ll n){
matrix ans(1, 0, 0, 1); //单位矩阵
while (n){
if (n & 1)
ans = ans * a;
a = a * a;
n >>= 1;
}
return ans;
}
int main()
{
cin >> a >> x >> MOD;
matrix M(1, a, 0, a);
matrix ans = qpow(M, x - 1);
printf("%lld\n", (ans.a1 + ans.a2) % MOD);
return 0;
}
思路:求出需要操作数,特判当k>=count,且n为偶数则(k-count)则必须为偶数,因为为奇数时,多的(k-count)可改变斜主对角线不影响
#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#define int long long
const int maxn=1e3+10;
using namespace std;
int a[maxn][maxn];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
int Count = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (a[i][j] != a[n+1- i][n+1- j])
Count++;
}
}
Count /= 2;
if (Count <= k && (n & 1 || (k - Count) % 2 == 0)) {
cout << "YES" << '\n';
}
else {
cout << "NO" << '\n';
}
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
A.TubeTube Feed
思路:贪心t--,如果t>=要观看时间&&价值>Max就更新
#include<bits/stdc++.h>
#include<iostream>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#define int long long
const int maxn=2e5+10;
using namespace std;
int a[maxn], b[maxn];
void solve() {
int n, t;
cin >> n >> t;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int j = 1; j <= n; j++) {
cin >> b[j];
}
int Max = 0, flag = -1;
t++;
for (int i = 1; i <= n; i++) {
t--;
if (t >= a[i]&&b[i]>Max) {
Max = max(Max, b[i]);
flag = i;
}
}
cout << flag << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
}
B.Karinaand Array
思路:排序,比较最小的两位乘和最大两位乘
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#define int long long
const int maxn=2e5+10;
using namespace std;
int a[maxn];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a +n+ 1);
cout << max(a[1] * a[2], a[n - 1] * a[n])<<'\n';
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
}
C - Bun Lover
思路:规律结果n * n + 2 + 2 * n
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#include<math.h>
#include<map>
#define int long long
const int maxn=2e5+10;
using namespace std;
int a[maxn];
void solve(){
int n;
cin >> n;
cout << n * n + 2 + 2 * n << '\n';
}
signed main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
}
Super - Permutation
思路:先预处理前缀和,可根据构造[n,1,n-2,3...]的形式,必定有一项是所有的和,
于是判断所有和%n是否为0,是重复-1,不是格式输出
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#define int long long
using namespace std;
const int maxn = 2e5 + 10;
int a[maxn];
void solve() {
int n;
cin >> n;
if (n == 1) {
cout << 1;
}
else {
if (a[n] % n == 0) {
cout << "-1";
}
else {
int i = 1;
int j = n;
n = n / 2;
while (n--) {
cout << j << ' ' << i << ' ';
i += 2;
j -= 2;
}
}
}
cout << '\n';
}
void init() {
a[0] = 0;
for (int i = 1; i < maxn; i++) {
a[i] = a[i - 1] + i;
}
}
signed main()
{
ios::sync_with_stdio(false);
init();
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
超星项目进程
1.改变了界面定时器刷新界面的功能,转换成在tab的selectionchanged上定义方法刷新界面,
刷新界面的模式为得到数据库更新的数据后,重新在list view中添加item
2.实现点击listview的item出现弹框功能:在listView2.getSelectionModel().selectedItemProperty().addListener()增加监听方法调出新界面