A Collecting Coins
B Collecting Packages
C Product of Three Numbers
D MEX maximizing
E - Obtain a Permutation
#include
using namespace std;
template<class T> inline void read(T &x){
x=0; char c=getchar(); int f=1;
while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
void solve()
{
int a, b, c, n;
scanf("%d%d%d%d", &a, &b, &c, &n);
int ans, ma = max({a, b, c});
ans = 3*ma-a-b-c;
(ans<=n&&(n-ans)%3==0)?puts("YES"):puts("NO");
}
int main()
{
int t;
read(t);
while(t--)
solve();
return 0;
}
tips:这里我用的是vector来存点,也可以结构体,基本无差别。auto是万能变量,比较方便,但得用c++11以上编译器才能通过。
#include
#define debug(x) cout <<#x<<" = "<
#define gg cout <<"-------------QAQ---------------"<
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
x=0; char c=getchar(); int f=1;
while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 266666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
bool cmp(pii x, pii y)
{
if(x.fi==y.fi) return x.se<y.se;
return x.fi<y.fi;
}
void solve()
{
int n;
read(n);
vector<pii> a(n+10);
for(int i = 0; i < n; ++i) scanf("%d%d", &a[i].fi, &a[i].se);
a[n].fi = a[n].se = 0;
sort(a.begin(), a.begin()+n+1, cmp);
vector<pii> ans;
for(int i = 1; i <= n; ++i) {
int x, y;
x = a[i].fi-a[i-1].fi;
y = a[i].se-a[i-1].se;
if(x<0||y<0) {
puts("NO"); return;
}
ans.pb(pii(x, y));
}
puts("YES");
for(auto x:ans) {
while(x.fi--) putchar('R');
while(x.se--) putchar('U');
}
printf("\n");
}
int main()
{
int t;
read(t);
while(t--)
solve();
return 0;
}
#include
#define debug(x) cout <<#x<<" = "<
#define gg cout <<"-------------QAQ---------------"<
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
x=0; char c=getchar(); int f=1;
while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
void solve()
{
int n;
read(n);
vector<int> ans; //用来放因子
int t = n;
for(int i = 2; i*i <= n; ++i) {
while(t%i == 0) {
ans.pb(i); t /= i;
}
}
if(t > 1) ans.pb(t);
if(ans.size()<3) { //因子数小于三就是NO
puts("NO"); return;
}
int a,b,c;
a=ans[0];
b=ans[1];
int l = 2;
while(a == b) {
b*=ans[l];
l++;
if(l == ans.size()) {
puts("NO"); return;
}
}
c=1;
for(int i = l; i < ans.size();++i) c*=ans[i];//剩余因子全部给c
if(a==c||b==c) {
puts("NO"); return;
}
puts("YES");
printf("%d %d %d\n", a, b, c);
}
int main()
{
int t;
read(t);
while(t--)
solve();
return 0;
}
#include
#define debug(x) cout <<#x<<" = "<
#define gg cout <<"-------------QAQ---------------"<
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define ll long long
using namespace std;
typedef unsigned int ui;
typedef pair<int,int> pii;
struct node
{
int x, cnt;
node(){}
node(int _x, int _cnt) {
x = _x, cnt = _cnt;
}
};
struct cmp
{
bool operator()(const node& a, const node& b) {
if(a.cnt == b.cnt) return a.x < b.x;
return a.cnt < b.cnt;
}
};
set<node, cmp> s;
map<int, int> num;
int main()
{
int t, x;
scanf("%d%d", &t, &x);
for(int i = 0; i < x; ++i) s.insert(node(i,0));
while(t--) {
int temp;
scanf("%d",&temp);
num[temp%x]++;
s.insert(node(temp%x, num[temp%x]));
s.erase(node(temp%x, num[temp%x]-1));
auto tt = s.begin();
// debug(tt->x);
// debug(tt->cnt);
printf("%d\n", (tt->cnt)*x+tt->x);
}
return 0;
}
当然D题也可以用线段树来维护,不推荐,我试着玩
#include
#define debug(x) cout <<#x<<" = "<
#define gg cout <<"-------------QAQ---------------"<
#define fi first
#define se second
#define pb push_back
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
const int N = 4066666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
struct node {
int x, cnt;
node(){}
node(int _x, int _cnt) {
x = _x, cnt = _cnt;
}
};
node MIN[N];
map<int, int> num;
node min(node x, node y)
{
if(x.cnt == y.cnt) {
if(x.x < y.x) return x;
return y;
}
if(x.cnt < y.cnt) return x;
return y;
}
void build(int l, int r, int rt)
{
if(l == r) {
MIN[rt].cnt = 0;
MIN[rt].x = l;
return ;
}
int m = (l+r)>>1;
build(lson);
build(rson);
MIN[rt] = min(MIN[rt<<1], MIN[rt<<1|1]);
}
void update(int p, int l, int r, int rt)
{
if(l == r) {
MIN[rt].cnt++;
return ;
}
int m = (l+r)>>1;
if(p <= m) update(p, lson);
else update(p, rson);
MIN[rt] = min(MIN[rt<<1], MIN[rt<<1|1]);
}
int main()
{
int q, x;
scanf("%d%d", &q, &x);
for(int i = 1; i <= x; ++i) num[i] = 0;
build(1, x, 1);
while(q--) {
int temp;
scanf("%d", &temp);
update(temp%x+1, 1, x, 1);
printf("%d\n", (MIN[1].cnt)*x+MIN[1].x-1);
}
return 0;
}
#include
#define debug(x) cout <<#x<<" = "<
#define gg cout <<"---------------QAQ---------------"<
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define ll long long
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
#define inf 0x3f3f3f3f
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1|1
using namespace std;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
x=0; char c=getchar(); int f=1;
while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 4066666;
void FAST(){ios::sync_with_stdio(false);cin.tie(0);}
int n, m;
int main()
{
scanf("%d%d", &n, &m);
vector<vector<int> > a(n+1, vector<int>(m+1));
for(int i = 0; i < n; ++i) {
for(int j = 0; j < m; ++j)
{
scanf("%d", &a[i][j]); a[i][j]--;
}
}
int ans = 0;
for(int j = 0;j < m; ++j) {
vector<int> s(n+1);
for(int i = 0; i < n; ++i) s[i] = i+n;
for(int i = 0; i < n; ++i) {
if(a[i][j]>=n*m||a[i][j]%m != j) continue;
int temp = (i-a[i][j]/m)+n; temp %= n;
s[temp]--;
}
ans += *min_element(s.begin(), s.begin()+n);
}
printf("%d\n", ans);
return 0;
}
``
###### F看下面的博客吧,菜鸡的我不会。。。
###### 分享一个大佬写完的题解:https://www.cnblogs.com/StarRoadTang/p/12230408.html