A
题意:从a位置到b位置去, 问最短花费.
思路: 估计也是我比较傻 fst的时候这题给挂了 ... 很显然, 当a位置与b位置数字相同时花费为0, 那么不同时呢? 比如 a位置是1 , b位置是0, 那么你要从1到0的最小花费其实是1 .. 为什么呢?
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
const int qq = 1e5 + 10;
char str[qq];
ll num[qq];
int main(){
int n, a, b;
scanf("%d%d%d", &n, &a, &b);
scanf("%s", str+1);
if(str[a] == str[b]) cout << 0 << endl;
else cout << 1 << endl;
return 0;
}
B
题意:给出n和k, 按照它的规则问第k个是哪个数字
思路:每次的奇数位置就是当前遍历的数字
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
const int qq = 1e5 + 10;
ll num[qq];
ll c[qq];
int main(){
ll n, k; cin >> n >> k;
int c = 0;
while(k >= 2){
if(k%2 == 1){
cout << c+1 << endl;
return 0;
}
k /= 2;
c++;
}
if(k == 1)
cout << c + 1 << endl;
return 0;
}
C
题意: 2/n = 1/x + 1/y + 1/z, 问是否存在x, y, z
思路:2/n = 1/n + 1/n, 那么问题就转化求1/n = 1/a + 1/b
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cctype>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;
const int qq = 1e5 + 10;
ll num[qq];
int main(){
ll n; cin >> n;
if(n == 1){
cout << -1 << endl;
return 0;
}
cout << n << " " << n+1 << " " << n*(n+1) << endl;
return 0;
}