SGU 169

题意:求k位数里面有多少个是完美数,完美数的定义就是n是好数,n+1也是好数,那么n就是完美数,好数就是n%p(n)==0&&p(n)!=0,p(n)=a1*...*an

收获:找规律

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 1e5+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int bit(ll n){
int ret = ;
while(n) n/=,ret++;
return ret;
}
//ll p(ll n){
// ll ret = 1;
//// dd(n)
// while(n) ret*=(n%10),n/=10;
//// de(ret)
// return ret;
//}
//bool check(ll n){
// ll tmp = p(n);
// if(tmp==0) return false;
// if(n%tmp==0) return true;
// return false;
//}
//bool ok(ll n){
// if(check(n)&&check(n+1)) return true;
// return false;
//}
int main(){
// rep(i,1,1e9+1) {
// if(ok(i)) {
// dd(bit(i))de(i)
// }
// }
qc;
int k;
cin>>k;--k;
if(!k) printf("");
else {
if(k%==) printf("");
else if(k%==) printf("");
else printf("");
}
return ;
}

SGU 172

题意:m个人,每个人选择了两个考试,那么这两个考试不能在同一天考(n个考试),问你能不能满足所有的人

收获:dfs染色

#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl;
#define dd(x) cout<<#x<<"="<<x<<" ";
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define ll long long
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
#define pii pair<int,int>
#define pdd pair<double,double>
#define pdi pair<double,int>
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define ull unsigned long long
#define ll long long
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define db double
#define all(a) a.begin(),a.end()
const int mod = 1e9+;
const int maxn = 2e2+;
const double eps = 1e-;
using namespace std;
bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=;a%=mod; if(b<) return ; for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
ll x=,f=;char ch=getchar();
while (ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while (ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n,m,u,v;
int a[maxn][maxn];
int col[maxn];
vector<int> ans;
void init(){
mt(col,-);ans.clear();
rep(i,,) rep(j,,) a[i][j] = ;
}
bool dfs(int u,int c){
col[u] = c;
rep(i,,n+){
if(a[u][i]){
a[u][i]=a[i][u]=;
if(col[i]==-) { if(!dfs(i,c^)) return false; }
else if(col[i]==c) return false;
}
}
return true;
}
int main(){
init();
scanf("%d%d",&n,&m);
rep(i,,m) scanf("%d%d",&u,&v),a[u][v]=a[v][u]=;
rep(i,,n+) if(col[i]==-) {
if(!dfs(i,)) return puts("no"),;
}
puts("yes");
rep(i,,n+) if(col[i]) ans.pb(i);
printf("%d\n",sz(ans));
rep(i,,sz(ans)) printf("%d%c",ans[i]," \n"[i+==sz(ans)]);
return ;
}

今天的SGU炸了,我登不上,决定先去睡觉了,明天至少4题

05-11 17:53