A Soft Drinking
就是参量有点多,看看题
// Problem: A - Soft Drinking
// Contest: Virtual Judge - Codeforces Beta Round #107(Div2) [Cloned]
// URL: https://vjudge.net/contest/439203#problem/A
// Memory Limit: 262 MB
// Time Limit: 2000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int n, k, l, c, d, p, nl, np;
int main(){
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
int a = k * l;
int b = c * d;
cout << min(a / nl, min(b, p / np)) / n;
re 0;
}
B Phone Numbers
就是一个结构体排序,判断好每一个电话属于哪一个然后按结构体排序就好了
(毒瘤题,调了老半天
// Problem: B-电话号码
// Contest: Virtual Judge - Codeforces Beta回合#107(Div2)[克隆]
// URL: https://vjudge.net/contest/439203#problem/B
// Memory Limit: 1024 MB
// Time Limit: 1000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int n;
struct nope{
char name[25];
int girl;
int taxi;
int pz;
int id;
}a[110];
int check(char s[]){
char num[20];
int cnt = 0;
for(int i = 0; s[i]; i++){
if(s[i] != '-')
num[cnt++] = s[i] - '0';
}
int t = 1;
for(int i = 1; i < cnt; i++){
if(num[i] >= num[i - 1]){
t = 0;
break;
}
}
if(t){
return 2;
}
t = 1;
for(int i = 1; i < cnt; i++){
if(num[i] != num[i - 1]){
t = 0;
break;
}
}
if(t){
return 1;
}
else{
return 3;
}
}
bool cmp_g(nope a, nope b){
if(a.girl > b.girl)
return a.girl > b.girl;
if(a.girl == b.girl)
return a.id < b.id;
return a.girl > b.girl;
}
bool cmp_t(nope a, nope b){
if(a.taxi > b.taxi)
return a.taxi > b.taxi;
if(a.taxi == b.taxi)
return a.id < b.id;
return a.taxi > b.taxi;
}
bool cmp_p(nope a, nope b){
if(a.pz > b.pz)
return a.pz > b.pz;
if(a.pz == b.pz)
return a.id < b.id;
return a.pz > b.pz;
}
int main(){
cin >> n;
for(int i = 1; i <= n; i++){
int m;
scanf("%d%s", &m, a[i].name);
a[i].id = i;
while(m--){
char num[20];
scanf("%s", num);
int t = check(num);
if(t == 1){
a[i].taxi++;
}
else if(t == 2){
a[i].pz++;
}
else{
a[i].girl++;
}
}
}
sort(a + 1, a + 1 + n, cmp_t);
printf("If you want to call a taxi, you should call:");
if(a[1].taxi == 0){
for(int i = 1; i <= n; i++){
cout << " " << a[i].name;
if(i == n) cout << ".\n";
else cout << ",";
}
}
else
for(int i = 1; i <= n; i++){
if(a[i].taxi){
cout << " " << a[i].name;
}
if(!a[i + 1].taxi || a[i + 1].taxi < a[i].taxi){
cout << ".\n";
break;
}
else{
cout << ",";
}
}
sort(a + 1, a + 1 + n, cmp_p);
printf("If you want to order a pizza, you should call:");
if(a[1].pz == 0){
for(int i = 1; i <= n; i++){
cout << " " << a[i].name;
if(i == n) cout << ".\n";
else cout << ",";
}
}
else
for(int i = 1; i <= n; i++){
if(a[i].pz){
cout << " " << a[i].name;
}
if(!a[i + 1].pz || a[i + 1].pz < a[i].pz){
cout << ".\n";
break;
}
else{
cout << ",";
}
}
sort(a + 1, a + 1 + n, cmp_g);
printf("If you want to go to a cafe with a wonderful girl, you should call:");
if(a[1].girl == 0){
for(int i = 1; i <= n; i++){
cout << " " << a[i].name;
if(i == n) cout << ".\n";
else cout << ",";
}
}
else
for(int i = 1; i <= n; i++){
if(a[i].girl){
cout << " " << a[i].name;
}
if(!a[i + 1].girl || a[i + 1].girl < a[i].girl){
cout << ".\n";
break;
}
else{
cout << ",";
}
}
}
C Win or Freeze
这题需要好好读题(我一开始没读明白,然后队友给我指点了一下我就知道该用什么方法了
一个人赢的条件是下一个人只能选这个人选的这个数本身和1就算这个人赢了
可能描述的有点混乱,样例解释也很好说明了
第6个只有两个非平凡除数:2和3。写了2号和3号是不可能的,所以两人都赢了,所以6号就是输的数字。玩家可以移动,在30号后写6号;6,我们知道,这是一个失败的数字。因此,这一举动将给我们带来胜利。
(机翻)
或者我以样例2说明
input
30
output
1 6
一开始数是30,第一个人可以选2、3、5、6、10、15,第一个选了6这个数,第二个人只能选6的因子,即2或者3,那么第二个人无论选哪个,它第一个人都不能再选了,这时候就判第一个人赢
那么我们很容易就想到了,这个数就是质数啊!
题目要求每个人都要以尽可能赢的方向去考虑,第一个人第一个选,要让第一个人赢就得让第二个人只能选包含除了1和它本身以外的数
那么我让第二个人只能选只有两个质因子的数就可以了,那第一个人就选他的除数就好了,那这很自然的就联想到了质因数分解
// Problem: C - Win or Freeze
// Contest: Virtual Judge - Codeforces Beta Round #107(Div2) [Cloned]
// URL: https://vjudge.net/contest/439203#problem/C
// Memory Limit: 262 MB
// Time Limit: 2000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
bool is_prime(ll n){
if(n < 2) return 1;
for(ll i = 2; i * i <= n; i++){
if(n % i == 0){
return 0;
}
}
return 1;
}
int main(){
ll n;
cin >> n;
int t = is_prime(n);
if(t){
cout << 1 << endl << 0;
return 0;
}
ll x = n;
vector<ll> ans;
int cnt = 0;
for (ll i = 2; i <= x / i && cnt < 5; i ++ ) // 没有必要全算出来,算几个就行,因为我觉得可能会超时,结果是上面判素数的时候ll爆了
if (x % i == 0 && cnt < 5)
{
while (x % i == 0 && cnt < 5)
x /= i, ans.push_back(i), cnt++;
}
if (x > 1) ans.push_back(x);
// sort(ans.begin(), ans.end());
int l = ans.size();
if(l <= 2){ // 没有两个以上那肯定2赢
cout << 2 << endl;
re 0;
}
cout << 1 << endl;
cout << ans[0] * ans[1];
re 0;
}
D Quantity of Strings
题意:现在有一个长度为N的字符串,它的字典集为 M .也就是说每一位有M 种不同的字母可以选.
对于这个字符串所有连续的长度为 K 的子串都必须是回文串,请问有多少种不同的方案。
参考了一篇blog,也有代码更短的,但是我觉得冰渣鸡更好理解一点
// Problem: D - Quantity of Strings
// Contest: Virtual Judge - Codeforces Beta Round #107(Div2) [Cloned]
// URL: https://vjudge.net/contest/439203#problem/D
// Memory Limit: 262 MB
// Time Limit: 2000 ms
// Code by: ING__
//
// Powered by CP Editor (https://cpeditor.org)
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
#define ll long long
#define re return
#define Endl "\n"
#define endl "\n"
using namespace std;
typedef pair<int, int> PII;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
const int N = 2010;
// 结构体版
struct ufss{
int f[N];
void init(int n){
for(int i = 1; i <= n; i++){
f[i] = i;
}
}
int query(int p){
if(f[p] == p) return p;
else{
int v = query(f[p]);
f[p] = v;
return v;
}
}
void merge(int p1,int p2){
int f1 = query(p1);
int f2 = query(p2);
if(f1 != f2){
f[f1] = f2;
}
}
bool pd(int p1, int p2){
if(query(p1) == query(p2)) return true;
else return false;
}
int count(int n){
int ans = 0;
for(int i = 1; i <= n; i++) if(f[i] == i) ans++;
return ans;
}
}ufs;
long long ksm(long long a, long long b,long long p) {long long ans=1;while (b) {if (b&1) ans=ans*a%p; a=a*a%p; b>>=1;} return ans;}
int n, m, k;
int main(){
cin >> n >> m >> k;
ufs.init(n);
for(int i = 1; i + k - 1 <= n; i++){
for(int j = i, p = j + k - 1; p >= j; j++, p--){
ufs.merge(j, p);
}
}
cout << ksm(m, ufs.count(n), 1000000007);
re 0;
}