6198 number number number
太简单,裸的斐波那契快速幂
/* xzppp */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int MAXN = 1e5+17;
const int MAXM = 1e6+17;
const int MAXV = 2*1e3+17;
const int BIT = 15+3;
const int INF = 0x7fffffff;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 998244353;
struct matrix{
static const int MATRIX_N = 11;
LL a[MATRIX_N][MATRIX_N];
int row, col;
matrix():row(MATRIX_N),col(MATRIX_N){memset(a,0,sizeof(a));}
matrix(int x, int y):row(x),col(y){memset(a,0,sizeof(a));}
LL* operator [] (int x){return a[x];}
matrix operator * (matrix x){
matrix tmp(col, x.row);
for(int i = 0; i < row; i++)
for(int j = 0; j < col; j++) if(a[i][j])//稀疏矩阵优化
for(int k = 0; k < x.col; k++) if (x[j][k]){
tmp[i][k] += a[i][j] * x[j][k];
//mult(a[i][j], x[j][k], MOD);
tmp[i][k] %= MOD;
}
return tmp;
}
void operator *= (matrix x){*this = *this * x;}
matrix operator ^ (LL x){
matrix ret(row, col);
for (int i = 0; i < col; i++) ret[i][i] = 1;
matrix tmp = *this;
for (; x; x >>= 1, tmp *= tmp){if (x&1) ret *= tmp;}
return ret;
}
void print(){
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++) printf("%lld ",a[i][j]);
puts("");
}
}
};
int main()
{
#ifndef ONLINE_JUDGE
FFF
#endif
matrix src(2,2);
src.a[0][1] = src.a[0][0] = src.a[1][0] = 1;
src.a[1][1] = 0;
matrix rbq(2,1);
rbq.a[0][0] = 1;
rbq.a[1][0] = 0;
LL n;
while(cin>>n)
{
matrix temp(2,2);
temp = src^(2+2*n);
//temp.print();
cout<<(rbq*temp).a[0][0]-1<<endl;
}
return 0;
}
6201 transaction transaction transaction
本次比赛唯一对我来说有意义的题.先贴代码,等下写个具体的题解吧
/* xzppp */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int MAXN = 1e5+17;
const int MAXM = 1e6+17;
const int MAXV = 2*1e3+17;
const int BIT = 15+3;
const int INF = 0x7fffffff;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
int val[MAXN],ans,dp[MAXN][2];
vector<pii > G[MAXN];
void dfs(int pre,int now)
{
dp[now][0] = -val[now];
dp[now][1] = val[now];
for (int i = 0; i < G[now].size(); ++i)
{
if(G[now][i].second!=pre)
{
dfs(now,G[now][i].second);
dp[now][0] = max(dp[now][0],dp[G[now][i].second][0]-G[now][i].first);
dp[now][1] = max(dp[now][1],dp[G[now][i].second][1]-G[now][i].first);
}
}
ans = max(ans,dp[now][0]+dp[now][1]);
}
int main()
{
#ifndef ONLINE_JUDGE
FFF
#endif
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for (int i = 0; i <= n; ++i)
{
G[i].clear();
}
for (int i = 0; i < n; ++i)
cin>>val[i];
for (int i = 0; i < n-1; ++i)
{
int u,v,c;
scanf("%d%d%d",&u,&v,&c);
u--;v--;
G[u].PB(MP(c,v));
G[v].PB(MP(c,u));
}
ans = 0;
dfs(-1,0);
cout<<ans<<endl;
}
return 0;
}
6205 card card card
很简单一个题,几乎没有思维量.
/* xzppp */
#include <iostream>
#include <vector>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
#include <map>
#include <string>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;
#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MP make_pair
#define PB push_back
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int > pii;
typedef pair<LL,LL> pll;
typedef pair<double,double > pdd;
typedef pair<double,int > pdi;
const int MAXN = 1e6+17;
const int MAXM = 1e6+17;
const int MAXV = 2*1e3+17;
const int BIT = 15+3;
const int INF = 0x7fffffff;
const LL INFF = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9+7;
void get(int &x)
{
char c = getchar(); x = 0;
while(c < '0' || c > '9') c = getchar();
while(c <= '9' && c >= '0') x = x*10+c-48, c = getchar();
}
void put(int x)
{
int num = 0; char c[15];
while(x) c[++num] = (x%10)+48, x /= 10;
while(num) putchar(c[num--]);
putchar('\n');
}
int a[MAXN],b[MAXN],sum[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
FFF
#endif
int n;
while(cin>>n)
{
for (int i = 0; i < n; ++i)
{
get(a[i]);
}
for (int i = 0; i < n; ++i)
{
get(b[i]);
}
for (int i = 0; i < n; ++i)
{
a[i] = a[i]-b[i];
}
sum[0] = a[0];
int mn = 0,mnp = 0;
for (int i = 1; i < n; ++i)
{
sum[i] = sum[i-1] + a[i];
if(sum[i]<=mn)
{
mn = sum[i];
mnp = i;
}
}
cout<<(mnp+1)%n<<endl;
}
return 0;
}