比赛连接
签到题:
直接模拟即可。
#include
using namespace std;
typedef long long ll;
void solve() {
int n, v, m, a;
int cnt = 0, ans = 0;
scanf("%d%d%d%d", &n, &v, &m, &a);
for (int i = 1; i <= n; ++i) {
cnt++;
ans += v;
if (cnt == m) {
v += a;
cnt = 0;
}
}
printf("%d\n", ans);
}
int main () {
solve();
return 0;
}
还是模拟
#include
using namespace std;
typedef long long ll;
void solve() {
double x;
scanf("%lf", &x);
double ans = 0;
if (x >= 90) {
ans = 4.0;
} else if (x >= 60 && x < 90) {
ans = 4.0 - (90 - x) * 0.1;
} else {
int y = sqrt(x) * 10;
x = y;
if (x >= 60 && x < 90) {
ans = 4.0 - (90 - x) * 0.1;
} else {
ans = 0.0;
}
}
printf("%0.1f\n", ans);
}
int main () {
solve();
return 0;
}
简单排序,自定义排序规则。
#include
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 5;
struct Node {
int t, k, ind;
}node[MAXN];
bool cmp(Node a, Node b) {
if (a.k * a.t == b.k * b.t) {
if (a.k == b.k) {
return a.ind < b.ind;
}
else {
return a.t > b.t;
}
}
return a.k * a.t > b.k * b.t;
}
void solve() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &node[i].t, &node[i].k);
node[i].ind = i;
}
sort(node + 1, node + n + 1, cmp);
for (int i = 1; i <= n; ++i) {
if (i == n) {
printf("%d\n", node[i].ind);
} else {
printf("%d ", node[i].ind);
}
}
}
int main () {
solve();
return 0;
}
利用两个map作映射关系,用时间去映射文件名,文件名去映射时间,一一对应。然后进行四个操作即可。
#include
using namespace std;
typedef long long ll;
map<string, int> gt;
map<int, string> gf;
void solve() {
int n, cnt = 0;
cin >> n;
string f1, s1;
while(n--) {
cin >> f1;
if (f1[0] != 'l') {
cin >> s1;
if (f1 == "touch") {
if (!gt.count(s1)) {
gt[s1] = ++cnt;
gf[cnt] = s1;
}
} else if (f1 == "rename") {
string yyy;
cin >> yyy;
if (gt.count(s1) && gt.count(yyy) == 0) {
int t = gt[s1];
gf[t] = yyy;
gt.erase(s1);
gt[yyy] = t;
}
} else if (f1 == "rm"){
int t = gt[s1];
gt.erase(s1);
gf.erase(t);
}
} else {
for (map<int,string>::iterator it = gf.begin(); it!=gf.end(); ++it) {
cout << (it->second) << "\n";
}
}
}
}
int main () {
solve();
return 0;
}
简单搜索,枚举n位中的每一位的情况,最大递归次数为610 ≈ 6e7,递归不会爆,而且不需要取模,最大情况也就610。
#include
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
ll n, k, sum = 0;
void dfs(int cnt, ll num) {
if (cnt == n) {
if (num % k == 0) {
sum++;
}
return;
}
for (int i = 1; i <= 6; ++i) {
dfs(cnt + 1, num * 10 + i);
}
}
void solve() {
scanf("%lld%lld", &n, &k);
dfs(0 , 0);
printf("%lld\n", sum);
}
int main () {
solve();
return 0;
}