Problem A – Avoiding accidents
有几行注释掉是应付small的
不过我写的也太不优拉,大数据n那么小就是看不到
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
string a[10];
int p[10];
int ca(int i,int j) {
if (a[i]==a[j]) return 4;
if (a[i].substr(1)==a[j].substr(0,3)) return 3;
if (a[i].substr(2)==a[j].substr(0,2)) return 2;
if (a[i].substr(3)==a[j].substr(0,1)) return 1;
return 0;
}
char s[1000],ans[1000];
bool calc() {
int sz=0;
Rep(j,4) s[sz++]=a[p[0]][j];
For(i,9) {
int caa=4-ca(p[i-1],p[i]);
Fork(j,4-caa,3) {
s[sz++]=a[p[i]][j];
}
}
s[sz]=0;
if (sz<=39) {
cout<<s;
// cout<<strlen(s)<<endl;
For(i,39-sz) putchar('A');
puts("");
return 1;
}
return 0;
}
int main()
{
freopen("A2.in","r",stdin);
freopen("a2.out","w",stdout);
int T=read();
while(T--) {
Rep(i,10) cin>>a[i];
Rep(i,10) p[i]=i;
do {
if (calc()) break;
// Rep(i,10) cout<<p[i]<<' ';cout<<endl;
}while(next_permutation(p,p+10));
// Rep(i,10) cout<<a[i];
// cout<<"AA"<<endl;
}
return 0;
}
Problem C – Counting swaps
big cases 没跑出来
这题有一个小trick,一个环可以拆成2个。。
最讨厌算法错了
C small (C big 得挂机。。)
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (1000000009)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
ll pow2(ll a,ll b,ll p) //a^b mod p
{
if (b==0) return 1%p;
if (b==1) return a%p;
ll c=pow2(a,b/2,p)%p;
c=c*c%p;
if (b&1) c=c*a%p;
return c%p;
}
ll inv(ll a){return pow2(a,F-2,F);}
int a[100000+10];
bool b[100000+10];
ll C(int n,int m) {
ll p=1;
For(i,m) p=mul(p,inv(i));
For(i,n-m) p=mul(p,inv(i));
For(i,n) p=mul(p,i);
return p;
}
#define MAXN (100000+10)
ll f[MAXN];
void calc() {
f[1]=1;
f[2]=1;
Fork(i,3,100000) {
f[i]=0;
For(j,i-1) {
ll p=mul(f[j],f[i-j]);
p=mul(p,C(i-2,j-1));
f[i]=add(f[i],mul(p,i));
}
f[i]=mul(f[i],inv(2));
}
}
ll fact(int n){
ll p=1;
if (n<=2) return 1;
Fork(i,3,n) p=mul(p,i);
return p;
}
ll dfs(vi ans) {
}
int main()
{
freopen("C2.in","r",stdin);
freopen("c2.out","w",stdout);
int T = read();
calc();
// For(i,10) cout<<f[i]<<endl;
while(T--) {
int n=read();
For(i,n) {
cin>>a[i];
}
MEM(b)
vi ans;
ans.clear();
For(i,n) if (!b[i]) {
int p=i,len=0;
while(!b[p]) {
b[p]=1;
p=a[p];
++len;
}
ans.pb(len);
}
sort(ans.begin(),ans.end());
ll an=1;
int sz=SI(ans),tot=n-sz;
// Rep(i,sz) cout<<ans[i]<<' ';cout<<endl;
Rep(i,sz) {
an=mul(an,f[ans[i]]);
an=mul(an,C(tot,ans[i]-1));
tot-=ans[i]-1;
}
cout<<an<<endl;
}
return 0;
}
Problem D – Dumb clicking
js语言阅读理解+提交答案大模拟
感谢交会我js的xjtu
The game is a browser-based JavaScript application. You can either open it from the online problem statement, or open the file d/easy.html or d/hard.html from the downloadable archive. You’ll need a reasonably modern browser to play. Old versions of Internet Explorer probably won’t work.
由于我没时间研究big 的随机(自己弱)
small case
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int x[12],y[12];
string rf[12]={"red s","green s","blue s","yellow s","orange s","pink s","red w","green w","blue w","yellow w","orange w","pink w"};
int main()
{
freopen("D.in","r",stdin);
freopen("d.out","w",stdout);
Rep(i,12) scanf("%d %d\n",&x[i],&y[i]);
char s[1000];
cout<<x[0]<<' '<<y[0]<<endl;
while(cin.getline(s,1000)) {
puts("next");
string S(s);
if (S.find("then")!=-1) {
Rep(i,12) {
if (S.find(rf[i])!=-1&&S.find(rf[i])<S.find("then")) cout<<x[i]<<' '<<y[i]<<endl;
}
Rep(i,12) {
if (S.find(rf[i])!=-1&&S.find(rf[i])>S.find("then")) cout<<x[i]<<' '<<y[i]<<endl;
}
}
else Rep(i,12) {
if (S.find(rf[i])!=-1) cout<<x[i]<<' '<<y[i]<<endl;
}
}
puts("done");
return 0;
}
Problem G – Greatest number
给你一个只有加剪乘的表达式,任意删除字符使结果最大
贪心:你删得只剩数字就是最大
注意前导0,只有0的表达式
#include<bits/stdc++.h>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define ForkD(i,k,n) for(int i=n;i>=k;i--)
#define RepD(i,n) for(int i=n;i>=0;i--)
#define Forp(x) for(int p=Pre[x];p;p=Next[p])
#define Forpiter(x) for(int &p=iter[x];p;p=Next[p])
#define Lson (o<<1)
#define Rson ((o<<1)+1)
#define MEM(a) memset(a,0,sizeof(a));
#define MEMI(a) memset(a,127,sizeof(a));
#define MEMi(a) memset(a,128,sizeof(a));
#define INF (2139062143)
#define F (100000007)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define SI(a) ((a).size())
typedef long long ll;
typedef unsigned long long ull;
ll mul(ll a,ll b){return (a*b)%F;}
ll add(ll a,ll b){return (a+b)%F;}
ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}
void upd(ll &a,ll b){a=(a%F+b%F)%F;}
int read()
{
int x=0,f=1; char ch=getchar();
while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();}
return x*f;
}
int main()
{
freopen("G2.in","r",stdin);
freopen("g2.out","w",stdout);
int T=read();
while(T--) {
string s;
cin>>s;
int l=s.length();
bool flag=0;
Rep(i,l) {
if (s[i]=='0') {
if (flag) cout<<s[i];
}
else if (isdigit(s[i])) {
cout<<s[i];
flag=1;
}
}
if (!flag) puts("0");else
cout<<endl;
}
return 0;
}