A.
int main() {
IOS;
// freopen("P1908_6.in","r",stdin);//读入数据
// freopen("P1908.out","w",stdout); //输出数据
int t;
cin >> t;
while(t--){
ll x, y;
cin >> x >> y;
if(y < x || y % x)
cout << "0 0" << endl;
else {
cout << "1 " << y / x << endl;
}
}
return 0;
}
B.
int main() {
IOS;
// freopen("P1908_6.in","r",stdin);//读入数据
// freopen("P1908.out","w",stdout); //输出数据
int t;
cin >> t;
while(t--){
//转换进制
string s;
cin >> s;
int ans = (s[0] - 'a') * 26 + (s[1] - 'a');
if(s[1] < s[0])
++ans;
ans -= (s[0] - 'a');
cout << ans << endl;
}
return 0;
}
C.
ll a[55];
void bitt(){
a[0] = 1;
a[1] = 2;
for (int i = 2; i <= 50; ++i){
a[i] = 2 * a[i - 1];
}
}
int main() {
IOS;
// freopen("P1908_6.in","r",stdin);//读入数据
// freopen("P1908.out","w",stdout); //输出数据
int t;
bitt();
cin >> t;
while(t--){
//不该面向样例编程
string s, t;
cin >> s >> t;
bool flag = true;
for (int i = 1; i < 26; ++i){
char c = 'a' + i;
if(t.find(c) != string::npos) {
flag = false;
break;
}
}
if(flag) {//全是a
if(t.size() == 1){
cout << 1 << endl;
}
else
cout << -1 << endl;
}
else {
//有其它
if(t.find('a') == string::npos){
if(s.size() == 1)
cout << 2 << endl;
else
cout << a[s.size()] << endl;//啊这里怎么算啊
}
else {
cout << -1 << endl;
}
}
}
return 0;
}
D.
下次可以猜正常一点的结论
新知识:is_sorted()
群友给的新知识:
memset() cf会tle
pow也,但pow能写1/2次方,但精度不对
一定要去验证自己的想法,模拟看看
int main() {
IOS;
int t;
cin >> t;
while(t--){
int n;
cin >> n;
int a[maxn];
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
int s = 1;
if (n % 2 == 1)
s = 2;//啊这里好神奇,建议自己模拟21435
for (int i = s; i < n; i += 2){
if(a[i] > a[i + 1])
swap(a[i], a[i + 1]);
}
/*
这里还有几个对比方法
1.is_sorted
2.创个b数组,排序后和移动的a比较
3.直接看a[i]大不大于a[i + 1]
*/
cout << (is_sorted(a + 1, a + n + 1) ? "YES" : "NO") << endl;
}
return 0;
}
为什么需要从s%2开始:
n是数组 "a "的长度,所以如果数组 "a "的长度是偶数,你就从索引0开始检查相邻的元素,否则如果是奇数,你就从索引1开始检查相邻元素。这是因为如果你观察到,
关键句,结论性:如果长度是奇数,那么在所有的操作之后,"a "的第一个元素将保持在 "c "的第一个位置。
实际上我就是没观察出来哈…,推也推了很久,总之需要去多多模拟
第二天重推,我悟了!
在奇数中,无论其它数怎么排,第一个一定在中间,只有这唯一一个决策,所以它的位置是不可变的;而在偶数中,他可能有两种决策,在左或在右,是可以变化位置的!