题目大意:
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
LL f(LL n){
if(n == 0) return 1;
else return n * f(n - 1);
}
void solve(){
LL n; cin >> n;
cout << f(n) << endl;
}
int main(){
IOS;
int _ = 1;
// cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
void solve(){
LL x; int k;
cin >> x >> k;
LL fac = 1;
for (int i = 1; i <= k; i ++) {
fac *= 10;
LL a = x / fac, b = ceil(1.0 * x / fac);
a *= fac; b *= fac;
if(abs(a - x) < abs(b - x)) x = a;
else x = b;
}
cout << x << endl;
}
int main(){
IOS;
int _ = 1;
// cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想:
代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
LL a[N];
int idx;
LL b[N];
LL c[N];
map<LL,int> vis;
void solve(){
int n; cin >> n;
for(int i = 0; i < n; i ++) {
cin >> a[i];
if(vis[a[i]] == 0){
vis[a[i]] = 1;
b[idx ++] = a[i];
}
}
sort(b, b + n, greater<LL>());
for(int i = 0; i < n; i ++){
int t = lower_bound(b, b + idx, a[i], greater<LL>()) - b;
c[t] ++;
}
for(int i = 0; i < n; i ++){
cout << c[i] << endl;
}
}
int main(){
IOS;
int _ = 1;
// cin >> _;
while(_ --){
solve();
}
return 0;
}
题目大意:
思想:
map<LL, set<LL>>
来快速查询。代码:
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define re register
#define fi first
#define se second
#define endl '\n'
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const double eps = 1e-6, PI = acos(-1);
map<LL, vector<LL>> dx, dy;
void solve(){
LL l, w, x, y; cin >> l >> w >> x >> y;
map<LL,set<LL>> dx, dy;
int n; cin >> n;
while(n --){
LL a, b;
cin >> a >> b;
dx[a].insert(b);
dy[b].insert(a);
}
for (auto &&i : dx){
i.second.insert(0);
i.second.insert(w + 1);
}
for (auto &&i : dy){
i.second.insert(0);
i.second.insert(l + 1);
}
int q; cin >> q;
while(q --> 0){
char op;
LL k;
cin >> op >> k;
if(op == 'L'){
LL ny = y - k;
if (dx.find(x) == dx.end()) {
y = max(ny, (LL)1);
}
else{
auto it = dx[x].lower_bound(y);
it = prev(it);
y = max(*it + 1, ny);
}
}
else if(op == 'R'){
LL ny = y + k;
if (dx.find(x) == dx.end()) {
y = min(ny, w);
}
else{
auto it = dx[x].lower_bound(y);
y = min(*it - 1, ny);
}
}
else if(op == 'U'){
LL nx = x - k;
if (dy.find(y) == dy.end()) {
x = max(nx, (LL)1);
}
else{
auto it = dy[y].lower_bound(x);
it = prev(it);
x = max(*it + 1, nx);
}
}
else{
LL nx = x + k;
if (dy.find(y) == dy.end()) {
x = min(nx, l);
}
else{
auto it = dy[y].lower_bound(x);
x = min(*it - 1, nx);
}
}
cout << x << ' ' << y << endl;
}
}
int main(){
IOS;
int _ = 1;
// cin >> _;
while(_ --){
solve();
}
return 0;
}