其中B、F、H、J四题现在看都不太容易,以后有机会再拿出来看看
题目链接
网站链接
题目大意:给定两个矩阵A和B,其中
A = [ 1 1 0 1 ] , B = [ 0 1 − 1 0 ] A= \begin{bmatrix} 1 & 1\\ 0 & 1 \end{bmatrix} , B=\begin{bmatrix} 0&1\\ -1&0 \end{bmatrix} A=[1011],B=[0−110]
现在说有一个矩阵
X = [ a b c d ] X= \begin{bmatrix} a & b\\ c & d \end{bmatrix} X=[acbd]
其中, a d − b c = 1 , a b c d = 0 ad-bc=1,abcd=0 ad−bc=1,abcd=0现在给定整数 a 、 b 、 c 、 d a、b、c、d a、b、c、d,保证 X X X能够由若干个 A A A和 B B B进行矩阵乘积得到,问如何组合,保证有解,输出一组即可,转化成数学语言是 − 1 0 5 ≤ a i ≤ 1 0 5 -10^5\leq a_i\leq 10^5 −105≤ai≤105 c i ∈ { A , B } c_i\in \{A,B\} ci∈{A,B} X = ∏ i c i a i X=\prod_ic_i^{a_i} X=i∏ciai
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 100;
const double eps = 1e-6;
int Data[MAXN];
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
int a, b, c, d;
cin >> T;
while(T--){
cin >> a >> b >> c >> d;
if(c == 0){
if(a == 1){
cout << 1 << "\n" << "A" << " " << b << "\n";
}else{
cout << 2 << "\n" << "B " << 2 << "\n";
cout << 'A' << " " << -b << "\n";
}
}else if(b == 0){
if(d > 0){
cout << 3 << "\n";
cout << "B 1\n";
cout << "A " << -c << "\n";
cout << "B -1\n";
}else{
cout << 3 << "\n";
cout << "B -1\n";
cout << "A " << c << "\n";
cout << "B -1\n";
}
}else if(a == 0){
if(c > 0){
cout << 2 << "\n";
cout << "B -1\n";
cout << "A " << d << "\n";
}else {
cout << 3 << "\n";
cout << "B -1\n";
cout << "B 2\n";
cout << "A " << -d << "\n";
}
}else if(d == 0){
if(c > 0){
cout << 2 << "\n";
cout << "A " << a << "\n";
cout << "B -1\n";
}else{
cout << 3 << "\n";
cout << "B 2\n";
cout << "A " << -a << "\n";
cout << "B -1\n";
}
}
}
return 0;
}
cout << 189;
给出四个数 l 1 , r 1 , l 2 , r 2 l_1,r_1,l_2,r_2 l1,r1,l2,r2问 ∏ i = l 1 r 1 i \prod_{i=l_1}^{r1}i ∏i=l1r1i是不是 ∏ i = l 2 r 2 i \prod_{i=l_2}^{r2}i ∏i=l2r2i的约数
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e7 + 100;
const double eps = 1e-6;
int Data[MAXN];
int vis[MAXN];
int p[MAXN];
int Prime(){
int tot = 0;
for(int i=2;i<=10000000;i++){
if(!vis[i]) p[tot++] = i;
for(int j=0;j<tot&&p[j]*i<=10000000;j++){
vis[i*p[j]] = 1;
if(i % p[j] == 0) break;
}
}
return tot;
}
int divide(int n, int p){
int ans = 0;
while(n){
ans += n / p;
n /= p;
}
return ans;
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int T;
int a, b, c, d;
cin >> T;
int tot = Prime();
while(T--){
cin >> a >> b >> c >> d;
bool flag = true;
for(int i=0;i<tot;i++){
int num1 = divide(a - 1, p[i]);
int num2 = divide(b, p[i]);
int num3 = divide(c - 1, p[i]);
int num4 = divide(d, p[i]);
if(num1-num2+num4-num3 < 0){
flag = false;
break;
}
}
if(flag) cout << "Yes\n";
else cout << "No\n";
}
return 0;
}
两人博弈,给出两人起点,图上路径,1号玩家先走,谁先碰到对方谁就赢了,问1号玩家是否能赢
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const ll INF = 2147483647;
const int MAXN = 2e6+100;
int head[MAXN];
int vis[MAXN];
int cnt;
ll dis[MAXN];
struct T{
int id;
int dis;
bool operator < (const T &a) const{
return a.dis < dis;
}
};
struct Edge{
int next;
int to;
ll value;
}edge[MAXN];
void init(int n){
memset(head,-1,sizeof head);
for(int i=0;i<=n;i++) dis[i] = INF;
cnt = 0;
}
void Add_Edge(int u, int v, ll value){
edge[cnt].to = v;
edge[cnt].value = value;
edge[cnt].next = head[u];
head[u] = cnt++;
}
void dijstra(int s){
priority_queue<T> q;
dis[s] = 0;
T now;
now.dis = dis[s];
now.id = s;
q.push(now);
while(!q.empty()){
T u = q.top();
q.pop();
if(vis[u.id]) continue;
vis[u.id] = 1;
for(int i=head[u.id];i!=-1;i=edge[i].next){
if(!vis[edge[i].to] && dis[edge[i].to] > edge[i].value + dis[u.id]){
dis[edge[i].to] = edge[i].value + dis[u.id];
now.id = edge[i].to;
now.dis = dis[edge[i].to];
q.push(now);
}
}
}
}
int main(){
int T, u, v;
scanf("%d", &T);
init(T);
for(int i=1;i<T;i++){
scanf("%d%d", &u, &v);
Add_Edge(u, v, 1);
Add_Edge(v, u, 1);
}
scanf("%d%d", &u, &v);
dijstra(u);
if(dis[v] & 1){
printf("Yes");
}else printf("No");
return 0;
}
题意需要仔细理解, n n n个人玩 Q Q QQ QQ飞车,有 x x x张地图,首先这 n n n个人先 b a n ban ban地图,每人只能 b a n ban ban一个,之后分成 m m m组,平均分组,分到同一组的人必须玩一个地图,但是不能玩同一组的人已经 b a n ban ban了的地图,问最少需要提供多少地图才能保证游戏正常进行
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 100;
const double eps = 1e-6;
int Data[MAXN];
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int t, n, m;
cin >> t;
while(t--){
cin >> n >> m;
if(n == m) cout << 2;
else if(m == 1) cout << n + 1;
else cout << 3;
cout << "\n";
}
return 0;
}
给出两个字符串,问第二个字符串是否是第一个字符串的子序列
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e6 + 100;
const double eps = 1e-6;
int Data[MAXN];
bool check(string s, string t){
int a = s.length();
int b = t.length();
int num = 0;
for(int i=0;i<a;i++){
if(s[i] == t[num]) num++;
if(num == b) break;
}
if(num == b) return true;
return false;
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
string s, t;
cin >> s >> t;
int a = s.length();
int b = t.length();
if(check(s, t)) cout << "Yes";
else cout << "No";
return 0;
}
给出 l l l和 k k k,问 [ l , l + 2 k ) [l,l+2k) [l,l+2k)区间内是不是 > k \gt k >k个质数
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
int main(){
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
ll l, k;
cin >> l >> k;
if(l != 2) cout << "No";
else{
if(k < 4) cout << "Yes";
else cout << "No";
}
return 0;
}