SGU 169
题意:求k位数里面有多少个是完美数,完美数的定义就是n是好数,n+1也是好数,那么n就是完美数,好数就是n%p(n)==0&&p(n)!=0,p(n)=a1*...*an
收获:找规律
#include#define de(x) cout<<#x<<"="< < =(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 #define pdd pair #define pdi pair #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+7;const int maxn = 1e5+5;const double eps = 1e-6;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==0?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=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}ll read(){ ll x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f;}int bit(ll n){ int ret = 0; while(n) n/=10,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("8"); else { if(k%6==0) printf("4"); else if(k%3==0) printf("3"); else printf("1"); } return 0;}
SGU 172
题意:m个人,每个人选择了两个考试,那么这两个考试不能在同一天考(n个考试),问你能不能满足所有的人
收获:dfs染色
#include#define de(x) cout<<#x<<"="< < =(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 #define pdd pair #define pdi pair #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+7;const int maxn = 2e2+5;const double eps = 1e-6;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==0?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=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){ if(b&1)res=res*a%mod;a=a*a%mod;}return res;}ll read(){ ll x=0,f=1;char ch=getchar(); while (ch<'0'||ch>'9'){ if(ch=='-')f=-1;ch=getchar();} while (ch>='0'&&ch<='9'){x=x*10+ch-'0';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 ans;void init(){ mt(col,-1);ans.clear(); rep(i,1,201) rep(j,1,201) a[i][j] = 0;}bool dfs(int u,int c){ col[u] = c; rep(i,1,n+1){ if(a[u][i]){ a[u][i]=a[i][u]=0; if(col[i]==-1) { if(!dfs(i,c^1)) return false; } else if(col[i]==c) return false; } } return true;}int main(){ init(); scanf("%d%d",&n,&m); rep(i,0,m) scanf("%d%d",&u,&v),a[u][v]=a[v][u]=1; rep(i,1,n+1) if(col[i]==-1) { if(!dfs(i,0)) return puts("no"),0; } puts("yes"); rep(i,1,n+1) if(col[i]) ans.pb(i); printf("%d\n",sz(ans)); rep(i,0,sz(ans)) printf("%d%c",ans[i]," \n"[i+1==sz(ans)]); return 0;}
今天的SGU炸了,我登不上,决定先去睡觉了,明天至少4题